1

I am using cap = cv.VideoCapture(0) When opening the camera to record video, the program will work but he prompts me ((process:10728): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed ) I don't know what the reason is, is it because of a problem with your cmake or a problem with the installation?

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
bwang
  • 13
  • 1
  • 5

2 Answers2

1

I had similar issue in version 3.4.4, compiled with gstreamer support. Syntax "cv2.VideoCapture(0)" just stopped working. I had all gst-* libraries installed, so most of answers wasn't helpful. But finally changing VideoCapture argument to full device path ("/dev/video0") helped.

dervan
  • 26
  • 1
  • 3
  • You're right ! I was using cv::VideoCapture::open(int index)and it sometimes worked, sometimes not ... I followed your advice and used cv::VideoCapture::open(device_filename) and it seems to wrok 100% of time ! Thanks a lot :) – Steven Dec 02 '18 at 22:55
1

Try:

cap = cv2.VideoCapture(0, cv2.CAP_V4L)

From this SO Answer

it works in my project

Zoe
  • 27,060
  • 21
  • 118
  • 148
Oscar C
  • 11
  • 1