Hey guys, I’ve been scowering the forums for a few days trying to figure this out but to no avail. I’m wondering if someone can help me with a pipeline for OpenCV. The webcam will open with this script, and it reports a size of 1280x720@30FPS but when i wave my hand in front of it it is clearly not 30 FPS, more like 5 or 10.
This is the output of v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 480x272
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 1024x576
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 1440x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.040s (25.000 fps)
Index : 1
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 480x272
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x360
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 800x600
Interval: Discrete 0.067s (15.000 fps)
Size: Discrete 1024x576
Interval: Discrete 0.100s (10.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.100s (10.000 fps)
and this is the pipeline:
cap = cv2.VideoCapture('v4l2src device=/dev/video0 io-mode=2 ! image/jpeg,framerate=30/1,width=1280,height=720,format=MJPG ! nvjpegdec ! videoconvert ! appsink', cv2.CAP_GSTREAMER')
I ran this in gst-launch-1.0 (I can’t remember the pipeline at the moment but will be looking for it) and it seems to have no issue when operating at 30FPS.
This is the basic python script I am using to open the camera to test the pipeline before I put it into my actual code.
import cv2
cap = cv2.VideoCapture('v4l2src device=/dev/video0 io-mode=2 ! image/jpeg,framerate=30/1,width=1280,height=720,format=MJPG ! nvjpegdec ! videoconvert ! appsink', cv2.CAP_GSTREAMER)
width= int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height= int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
print('Src opened, %dx%d @ %d fps' % (width,height,fps))
#writer= cv2.VideoWriter('video.mp4', cv2.VideoWriter_fourcc(*'DIVX'), 20, (width,height))
while True:
time.sleep(0.5)
ret,frame= cap.read()
# writer.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
#writer.release()
cv2.destroyAllWindows()
If anyone could please help me refine this pipeline I would be forever grateful.