Cannot identify device '/dev/video0' - video reading OpenCV 3.1
Hello,
I'm trying read the video from a camera connected to my computer using OpenCV.
I tried this first test, and I got the following error message :
"GStreamer Plugin: Embedded video playback halted; module v4l2src0 reported: Cannot identify device '/dev/video0'. OpenCV Error: Unspecified error (GStreamer: unable to start pipeline ) in cvCaptureFromCAM_GStreamer, file 'file_location'/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp, line 818 terminate called after throwing an instance of 'cv::Exception' what(): 'file_location'/opencv-3.1.0/modules/videoio/src/cap_gstreamer.cpp:818: error: (-2) GStreamer: unable to start pipeline in function cvCaptureFromCAM_GStreamer
Aborted"
Here is the code :
#include "opencv2/opencv.hpp"
#include <stdio.h>
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
{
std::cout << " Cannot open video" << std::endl;
return -1;
}
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructorcd ,,
return 0;
}
If someone has an idea that would be very helpful !
Thank you very much in advance.
Florence
Make sure, your video0 device exists. Use this command:
ls -ltr /dev/video*
to list the connected video devicesOh you're right, it actually doesn't exist. But I'm sure the camera is connected and recognized by the computer. I've also tried to replace
VideoCapture cap(0)
byVideoCapture cap(CV_CAP_XIAPI)
which actually works better as it doesn't crach, but the video cannot be opened...if you list the connected video devices, is there any device listed? (e.g. video1 or so). Also, are you using a virtual machine by any chance?
No there are no new devices when I plug the camera... But when I type
dmesg
then I see that the usb device is connected and recognized. And no, no virtual machine.