OpenCV can't find my USB webcam

I am trying to create an OpenCV application on my MacBook with built-in iSight camera. I grabbed some very simple code off the internet and ran it with no trouble. OpenCV automatically discovered the built-in webcam and ran properly but I can't get it to work with my USB webcam.

#include <stdio.h>
#include <opencv.hpp>

int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    /* initialize camera */
    capture = cvCaptureFromCAM(0);

    /* always check */
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!n" );
        return 1;
    }

    /* create a window for the video */
    cvNamedWindow( "Test", CV_WINDOW_AUTOSIZE );

    while( key != 'q' ) {
        /* get a frame */
        frame = cvQueryFrame( capture );

        /* always check */
        if( !frame ) break;

        /* display current frame */
        cvShowImage( "Test", frame );

        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
    }

    /* free memory */
    cvDestroyWindow( "Test" );
    cvReleaseCapture( &capture );

    return 0;
}

I compiled this with:

g++ webcam.c -o webcam -I/opt/local/include/opencv2 -I/opt/local/include -L/opt/local/lib -lopencv_core -lopencv_highgui

According to the documentation, by changing the line capture = cvCaptureFromCAM(0); to capture = cvCaptureFromCAM(1); I should be able to access the other webcam that I have plugged in but running the program gives me the error message: Warning: Max Camera Num is 0; Using camera 0 Warning: Max Camera Num is 0; Using camera 0

What steps can I take to get OpenCV to recognize that I have another camera connected to my USB drive?


This is based on windows experience, but I believe the main issue to be the same. (To get input from a logitech USB-camera on my laptop.)

As far as I recall; OpenCV does not support multiple cameras, and thereby not the choice of camera. I am guessing that you can easily run your build-in camera with the code you've shown. My solution to a similar problem was deactivating the build-in camera. Giving the USB camera the only "availavle" slot for your cvCaptureFromCAM(0) function.

I hope this can solve your problem, even though the solution is a little 'clunky'.

链接地址: http://www.djcxy.com/p/83774.html

上一篇: OpenCV + Ubuntu 11.04 + Macbook Pro:无法初始化网络摄像头?

下一篇: OpenCV找不到我的USB网络摄像头