I copied code from https://stackoverflow.com/a/34588758/210342 and used with default (built-in) camera, it worked. Then I attached USB camera, tested it with VLC and changed the code to open camera 1
:
cam = cv2.VideoCapture(1)
I check whether the camera is open cam.isOpened()
-- it is -- but the camera is not enabled (its hardware indicator, LED, is off) and indeed all I see on the screen is black frame.
Is there some extra special code to add in order to enable USB camera?
Compile and install: The following sample OpenCV python code explain how to open the device video node, set the resolution, grab the frame and then display the frame in preview window. # Check whether user selected camera is opened successfully. Release the camera, then close all of the imshow() windows.
Pretty much any logitech camera is great for openCV, the most common one being the C270. You can get wider-angle cameras but they are nearly $100, so it's usually easier to just glue a phone camera lens on for a wider FOV. The Pixy is really popular, and it has a bunch of code and libraries available online.
You can also refer this link here
https://devtalk.nvidia.com/default/topic/1027250/how-to-use-usb-webcam-in-jetson-tx2-with-python-and-opencv-/
Here he changes the line below to
cap = cv2.VideoCapture("/dev/video1") # check this
Before plugging in the camera, go to your terminal home
cd /dev
ls video
and then press tab, if you find only result as video0
, that means only webcam is present.video1
or video2
when you repeat the steps. Are you sure the usb camera is camera 1, i've done this before and had to use cv2.VideoCapture(0)
I ran into the same problem, turns out sometimes the webcam can take both slots 0 and 1.
So cam = cv2.VideoCapture(2)
worked for me. This was found using the cd /dev
-method above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With