1

我正在尝试使用 OpenCV 2.4.6 从 Macbook Pro 的 iSight 捕获帧,并在 Xcode 上使用 Apple LLVM 4.2 编译器构建。

但是,我没有收到任何帧。通常我会设置一个 while 循环来运行直到帧已满,但下面的循环运行约 30 秒而没有结果。我该如何调试呢?

void testColourCapture() {

    cv::VideoCapture capture = cv::VideoCapture(0); //open default camera
    if(!capture.isOpened()) {
        fprintf( stderr, "ERROR: ColourInput capture is NULL \n" );
    }
    cv::Mat capFrame;

    int frameWaits = 0;
    while (capFrame.empty()) {
        capture.read(capFrame);
        //capture >> capFrame;
        cvWaitKey(30);
        frameWaits++;
        std::cout << "capture >> capFrame " << frameWaits << "\n";
        if (frameWaits > 1000) {
            break;
        }
    }
    imshow("capFrame", capFrame);

}

我确保它不是多线程的。此外, capture.isOpened 始终返回 true。

编辑:似乎其他人遇到了这个问题:OpenCV won't capture from MacBook Pro iSight

编辑:我安装 opencv 的程序是:

$ sudo 端口自我更新

$ sudo 端口安装 opencv

然后,我将 libopencv_core.dylib、libopencv_highgui.dylib、libopencv_imgproc.dylib 和 libopencv_video.dylib 从 /opt/local/lib 拖到我的 Xcode 项目的 Frameworks 文件夹中

4

2 回答 2

2

OpenCV 2.4.6 已损坏,不适用于 iSight 摄像头。所以安装 2.4.5 代替。我为此编写了分步指南: http: //accidentalprogramming.blogspot.ch/2013/10/opencv-installation-on-mac-os-x.html

于 2013-10-18T19:29:26.047 回答
2

我让它使用以下代码:

VideoCapture cap = VideoCapture(0); // open the video file for reading

if ( !cap.isOpened() )  // if not success, exit program
{
    cout << "Cannot open the video file" << endl;
    return -1;
}

//cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

cout << "Frame per seconds : " << fps << endl;

namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

while(1)
{
    Mat frame;

    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
        cout << "Cannot read the frame from video file" << endl;
        break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}
于 2014-10-13T21:22:55.743 回答