1

Why does the following code work when my camera is connected to a USB 2.0 port, but when the camera is connected to a USB 3.0 port I get the "No Camera" error? I am running OpenCV 2.4 on Ubuntu 12.04 LTE 32 bit. I've seen this problem with other cameras and drivers also, so I suspect it might be a problem with Linux

#include <stdio.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"

using namespace cv;

int main(){

    Mat img;
    int imgw = 640;
    int imgh = 480;

    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened()){ // check if we succeeded
        printf("No camera\n");
        return -1;
    }
    cap.set(CV_CAP_PROP_FRAME_WIDTH,  imgw);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, imgh);

    namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );

    for( ; ; ){

        cap.read( img );

        imshow( "Display Image", img );

        if( waitKey( 5 ) == 27 ) break;

    }

    return 0;

};

EDIT: Also throws error through a USB 2.0 hub connected to a USB 3.0 port.

EDIT 2: Actually, this code works once after a restart. After that, the camera no longer shows up in /dev nor in the output of lsusb. None the USB 3.0 ports on that card work after one run of the program above.

Community
  • 1
  • 1
dmagree
  • 265
  • 1
  • 2
  • 10

1 Answers1

1

The problem seems to depend on the computer, or maybe more specifically, the USB card. I've tried this on two other computers now and it works fine.

So one solution: try a different computer.

dmagree
  • 265
  • 1
  • 2
  • 10