[Python+OpenCV] Problem with v4l2 videostreaming

I tried with video streaming with gst-launch code as following:

gst-launch-1.0 -v v4l2src device=/dev/video0 ! video/x-raw,framerate=25/1,width=640,height=480 ! xvimagesink -ev

I get perfect video streaming.

When i try to do it with a python code as following:

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
cap.set(5,25)
cap.set(15, 0.1)
while(cap.isOpened()):
ret, frame = cap.read()
print frame
cv2.imshow(‘frame’,frame)
if cv2.waitKey(1) & 0xFF == ord(‘q’):
break

cap.release()
cv2.destroyAllWindows()

I get the following error:
HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP
along with a very pixel distorted videostream.

What should I do?

Hi,

Do you build opencv with gstreamer and v4l2 options?
If not, please build opencv with the corresponding options.

Information can be found in this page:
http://dev.t7.ai/jetson/opencv/

Thanks.

I already built my opencv with gstreamer and v4l2 options. No luck.

I tried downloading from the provided link once again from scratch but the file size is becoming so big that the “make” step stops at 30% only. What should I do?

Hi,

We found that compiling opencv sometime hang the system with unknown reason.
Please re-start the device and make it again.

For your use-case, please make sure you open camera with the correct instruction.