OpenCV无法从iSight网络摄像头捕获图像

3
我无法使用以下OpenCV代码从我的网络摄像头捕获图像。
该代码可以显示本地AVI文件或视频设备中的图像。它在“test.avi”文件上运行良好。
当我使用默认网络摄像头(CvCapture * capture = cvCreateCameraCapture(0))时,程序可以检测到来自网络摄像头的图像大小,但是却无法显示图像
/我忘记提到我可以看到iSight正在工作,因为LED指示灯已经打开了/
有人遇到过同样的问题吗?
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
  • 调试库 *d.lib
  • WebCam 爱视特
  • Macbook 操作系统 win7 32位
  • VS2008

我有完全相同的问题,几乎相同的设置(win7 64)。我尝试过使用qt支持和不使用qt支持构建opencv,但都没有成功。 - mwahab
5个回答

3

我正在使用Macbook pro Mid 2012进行opencv 2.3的工作,我遇到了Isight相机的问题。不知何故,我通过简单调整Cvcapture参数以及帧宽度和高度来解决了这个问题:

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

您还可以将这些数字更改为您想要的帧宽度和高度。


1
你尝试过从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上)。如果不起作用,某种错误消息会很有帮助。


谢谢您的回复。问题还没有解决。当我检查“frame”时,行和列是正确的(480*640)。我不确定这个“frame”应该是什么样子的。我有一个关于这个“frame”的截图,您可以在这里找到它 http://dusijun.wordpress.com/2011/01/11/opencv-unable-to-capture-image-from-isight-webcam/ image 3 - Steven Du
摄像头能和其他程序一起使用吗?可能只是驱动程序的问题。 - etarion
最新更新!问题已解决!这恰好是OpenCV 2.2的一个bug以下是修复方法:http://dusijun.wordpress.com/2011/01/11/opencv-unable-to-capture-image-from-isight-webcam/[^] - Steven Du

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

0

-1

你为什么不试试呢?

capture=cvCaptureFromCam(0);

我觉得这个可能会起作用。

请告诉我它是否工作。


我觉得这是一个bug或驱动程序的问题。 - Steven Du

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接