1

After installing OpenCV4.0 on my RPi, i tried a simple script below with a Logitech USB Cam (720p) but at "cam = cv2.VideoCapture(0)" it gives me an error "(python:num process): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed"

import cv2

print('Start')

# initialize the camera
cam = cv2.VideoCapture(0)
ret, image = cam.read()

if ret:
    cv2.imshow('SnapshotTest',image)
    cv2.waitKey(0)
    cv2.destroyWindow('SnapshotTest')
    cv2.imwrite('/home/pi/SnapshotTest.jpg',image)

cam.release()
print('End')

Has anyone a clue why this happen?

Thanks!

Edit April 30th: Let me add that if I unplug my USB Cam from RPi then I have the following message: Then when I unplug the USB Cam, the process get out of hang state and return the following message: "VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV VIDEOIO ERROR: V4L: can't open camera by index 0 VIDIOC_REQBUFS: No such device"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.