OpenCV unable to capture image from isight webcam

I can not capture image from my webcam using following OpenCV code.

The code can show images from a local AVI file or a video device. It works fine on a "test.avi" file.

When I make use my default webcam(CvCapture* capture =cvCreateCameraCapture(0)), the program can detected the size of the image from webcam,but just unable to display the image .

/I forgot to mention that I can see the iSight is working because the LED indicator is turn on/

Anyone encounter the same problem?

cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );

CvCapture* capture =cvCreateFileCapture( "C:test.avi" ) ;// display images from avi file, works well 
// CvCapture* capture =cvCreateCameraCapture(0); //display the frame(images) from default webcam not work 

assert( capture );
IplImage* image;

while(1) {
 image = cvQueryFrame( capture );
   if( !image ) break;

  cvShowImage( "Example2", image );

  char c = cvWaitKey(33);
  if( c == 27 ) break;
}

cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );
  • opencv 2.2
  • Debug library *d.lib
  • WebCam isight
  • Macbook OS win7 32
  • VS2008

  • I'm working on opencv 2.3 with Macbook pro Mid 2012 and I had that problem with the Isight cam. Somehow I managed to make it work on opencv by simply adjusting the parameters of the Cvcapture and adjusting the frame width and height:

    CvCapture* capture = cvCaptureFromCAM(0);
    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 500 );
    cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 600 );
    

    You can also change these numbers to the frame width and height you want.


    Did you try the example from the opencv page?

    namely,

    #include "cv.h"
    #include "highgui.h"
    
    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;
    }
    

    Works on a macbook pro for me (although on OS X). If it doesn't work, some kind of error message would be helpful.


    尝试这个:

    int main(int, char**) {
        VideoCapture cap(0); // open the default camera
        if (!cap.isOpened()) {  // check if we succeeded
            cout << "===couldn't open camera" << endl;
            return -1;
        }
        Mat edges, frame;
        frame = cv::Mat(10, 10, CV_8U);
        namedWindow("edges", 1);
        for (;;) {
            cap >> frame; // get a new frame from camera
            cout << "frame size: " << frame.cols << endl;
            if (frame.cols > 0 && frame.rows > 0) {
                imshow("edges", frame);
            }
            if (waitKey(30) >= 0)
                break;
        }
        // the camera will be deinitialized automatically in VideoCapture destructor
        return 0;
    }
    
    链接地址: http://www.djcxy.com/p/80972.html

    上一篇: 网络摄像头“仍然销”捕获

    下一篇: OpenCV无法从isight网络摄像头捕获图像