Trouble with webcam opening on ubuntu 16.04 C++

asked 2017-10-16 11:18:00 -0500

I have tried to confirm that OpenCV is working on a new install I have just completed and found that I could open a jpeg and went on to check the web cam. I have installed cheese and found the web cam is working and drivers are all setup, as far as I could tell. I then went to find some example code to open the camera just to confirm it's all working and I am greeted with this message when I execute the program:

OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /opt/opencv/modules/videoio/src/cap_gstreamer.cpp, line 887
VIDEOIO(cvCreateCapture_GStreamer(CV_CAP_GSTREAMER_V4L2, reinterpret_cast<char *>(index))): raised OpenCV exception:

/opt/opencv/modules/videoio/src/cap_gstreamer.cpp:887: error: (-2) GStreamer: unable to start pipeline
 in function cvCaptureFromCAM_GStreamer

This is the example code I am trying to execute:

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int argc, char** argv)
{
    VideoCapture cap;
    // open the default camera, use something different from 0 otherwise;
    // Check VideoCapture documentation.
    if(!cap.open(0))
        return 0;
    for(;;)
    {
          Mat frame;
          cap >> frame;
          if( frame.empty() ) break; // end of video stream
          imshow("this is you, smile! :)", frame);
          if( waitKey(10) == 27 ) break; // stop capturing by pressing ESC 
    }
    // the camera will be closed automatically upon exit
    // cap.close();
    return 0;
}
edit retag flag offensive close merge delete

Comments

I am having this same issue on 16.04 with gstreamer 1.8.3. OpenCV installs and works fine, but the VideoCapture fails with the same error message. The webcame shows as '/dev/video0' and works with other programs like cheese and streamer. It's almost as if gstreamer recognizes it for a second (the webcam light turns on), but then errors out.

njthoma gravatar imagenjthoma ( 2017-10-18 15:44:53 -0500 )edit

I am having the exact same problem as njthoma.

mmartin4972 gravatar imagemmartin4972 ( 2020-01-14 12:04:05 -0500 )edit