Opencv: VideoCapture class webcam ERROR

Created on 16 Apr 2017  路  3Comments  路  Source: opencv/opencv

Issue

Error is raised when I run this example code from VideoCapture class documentation, http://docs.opencv.org/2.4/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture

#include "opencv2/opencv.hpp"    
#include "opencv2/highgui/highgui.hpp"
using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_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 destructor
    return 0;
}

_Error:_
libv4l2: error setting pixformat: Device or resource busy
VIDEOIO ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
VIDEOIO ERROR: libv4l unable to ioctl VIDIOCSPICT

My steps so far

Possible solutions

  • Must be webcam somehow pre-set to call VideoCapture open or constructor ?

Not working on both USB connected Logitech qc 3000 and build in webcam.
System Ubuntu 16.

I need to use video stream from webcam. ( later from more webcams)

invalid

All 3 comments

Maybe solved. Somehow the webcam wasn't freed by quiting one instance of program, so conflict was made by running it again. Also the strange behavior was caused by this line of example code
if(waitKey(30) >= 0) break;
making it stop almost by instant, I changed it to continue so stream is endless now.

Actually you should use the latest docs instead of 2.4 docs if you want correct tutorials and sample code. The link you provided is actually not working, so I do not know if the issue still arises in 3.2.

Device or resource busy

Problem is somewhere here.

Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org

Was this page helpful?
0 / 5 - 0 ratings