VideoIO Error: Pixel format unsupported?

asked 2014-09-21 19:04:39 -0500

potatoprogrammer gravatar image

I have a logitech usb camera attached to my computer running Ubuntu 14.04 LTS, but when I tried to use the camera to display a video feed, I got the following output:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV VIDIOC_G_FMT: Bad file descriptor VIDIOC_G_FMT: Bad file descriptor VIDIOC_STREAMON: Inappropriate ictl for device Frame size: -1 x -1 Cannot read a frame from video stream Unable to stop the stream.: Inappropriate ioctl for device

It worked on my other computer. Anyone know what's wrong? Code below:

#include "opencv2/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
    VideoCapture cap(0); // open the video camera no. 0

    if (!cap.isOpened())  // if not success, exit program
        cout << "Cannot open the video cam" << endl;
        return -1;

    double dWidth = cap.get(CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
    double dHeight = cap.get(CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("Camera Video",WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while (1)
        Mat frame;

        bool bSuccess =; // read a new frame from video

        if (!bSuccess) //if not success, break loop
            cout << "Cannot read a frame from video stream" << endl;

        imshow("MyVideo", frame); //show the frame in "MyVideo" window
        char c = waitKey(30);
        if (c == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
            cout << "esc key is pressed by user" << endl;
    return 0;
edit retag flag offensive close merge delete