OpenCV failed to capture isight webcam image

I cannot capture an image from my webcam using the following OpenCV code.

The code may display images from a local AVI file or video device. It works fine in the test.avi file.

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

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

Does anyone face 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
+3
source share
5 answers

opencv 2.3 Macbook pro Mid 2012, Isight. - opencv, Cvcapture :

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

.

+3

opencv?

,

#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;
}

macbook pro ( OS X). , - .

+1

:

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;
}
+1

capture=cvCaptureFromCam(0);

, .

.

-1

Source: https://habr.com/ru/post/1784753/


All Articles