I’m trying to make a first pass at opening up my webcam and doing some image labelling …
I’m trying to test a USB webcam .
The webcam is being recognized by lsusb and ls /dev/video* as /video1.
I’m trying to follow along this tutorial as well as this one and this one.
I’ve been able to install " gstreamer1.0-plugins-bad-faad
but notgstreamer1.0-plugins-bad-videoparsers (I got an error … which I think can be ignored because it should only be needed for IP cameras).
Either way, when I run my test script, I get the error: ... GStreamer: pipeline have not been created, along with a “could not read from resource” and “unable to start pipeline” error.
When trying to open Cheese, the camera is listed under “Devices” … but greyed out.
So assuming you have an X display running and DISPLAY set to this, you may check that you can display. The following uses a software video source so that we rule out a display issue before going into camera:
gst-launch-1.0 videotestsrc ! xvimagesink
If ok, let’s try using the camera. Be sure you plug it into full size USB connector, the micro-USB OTG is not able to acheive high bandwidth.
`import numpy as np
cap = cv2.VideoCapture("/dev/video1") # check this
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
if cv2.waitKey(1) & 0xFF == ord('q'):
# When everything done, release the capture
Does that mean I need to change the cap = cv2.VideoCapture("/dev/video1") line to the “gst-launch-1.0” line?
That doesn’t seem right.
Setting it to “/dev/video0” gives me a failed to create pipeline error
If you want monochrome frame, you may use a gstreamer pipeline leveraging jetson HW to do so:
cap = cv2.VideoCapture("v4l2src device=/dev/video0 ! image/jpeg, format=MJPG, width=640, height=480, framerate=30/1 ! nvv4l2decoder mjpeg=1 ! nvvidconv ! video/x-raw, format=GRAY8 ! appsink drop=1", cv2.CAP_GSTREAMER)
if not cap.isOpened() :
...error failed to open cam from gst backend
# Now you would read one channel gray8 frames