1
votes

I am using a basic USB webcam with OpenCV in python and it works as expected using a simple test script.

import cv2
cap = cv2.VideoCapture(0)
while True:
    ret, frame = cap.read() #capture a frame
    cv2.imshow('frame', frame) #display the frame
    if cv2.waitKey(1) & 0xff == ord('q'): #keep streaming video until the 'q' key is pressed
        break
cap.release()
cv2.destroyAllWindows()

I have also tested functionality using YawCam and the camera works as expected. However, I am now trying to use a USB over IP server. In this configuration, I can still stream video using YawCam but OpenCV returns blank frames. Does anyone have any suggestions as to what might cause this, possible solutions, or tests I should try?

Additional details

I am using the SIIG DS0611 USB IP Server. This allows me to connect the camera to my LAN at home instead of connecting the camera directly to the USB port on my computer. This is different from an IP camera in that my computer "thinks" the camera is connected directly to its USB port, so I don't think RTSP will work. I believe this because the "HD USB Camera" device shows up in my Device Manager under "Cameras" just like it does when I connect the camera directly to my computer's USB port. However, OpenCV only returns black or mostly black frames with some gibberish pixels when I run my code. OpenCV is able to connect and does recognize that the camera is opened. I have also tried adding various delays into the code to allow more time to initialize the camera and to read frames. Nothing has helped. YawCam doesn't have any issues so I know the camera/IP server are working well, but I need the camera to work in python.

1
Do you have any code example to help us help you?LoukMouk
I've updated my question to show the code I'm using. It is just a basic example, so I'm pretty sure the problem is in OpenCV.Joe Mac
I'm pretty sure the problem is in cap = cv2.VideoCapture(0). This works when you have a camera dirrectly plugged in your computer, but if the camera is distant, you'll need to change that 0 argument for your ip address or somehting! Look at this link -> answers.opencv.org/question/133/how-do-i-access-an-ip-cameraLoukMouk
The USB IP Server doesn't work that way. It comes with a driver that talks with the server and hides all the Ethernet stuff. As far as the Windows OS is concerned, the camera is connected directly to the USB port. The camera shows up under Device Manager as if it was plugged directly into the USB port. I wish it turned the USB camera into an IP camera but it does not.Joe Mac

1 Answers

0
votes

Its due to default OpenCV VideoCapture trying to use memory mapping. It appears local but direct memory mapping calls will not work as the image data is not actually on the client machines memory.

If the V4l2 api is used you can choose various methods to open the camera and it works if the slower methods are used. Memory mapping is usually the fastest so it's the default method OpenCV used to keep people from complaining about speed at the cost of confusing users doing "odd" things like usbip sharing.

Good luck.