2013-10-04 56 views
1

我試圖從Macbook Pro的iSight使用OpenCV 2.4.6捕獲幀,並在Xcode上使用Apple LLVM 4.2編譯器構建。從Macbook Pro iSight與Opencv捕獲

但是,我沒有收到任何幀。通常我會設置一個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 wont' capture from MacBook Pro iSight

編輯:我安裝OpenCV的程序是:

$ sudo的港口自更新

$ sudo的港口安裝OpenCV

然後,我將libopencv_core.dylib,libopencv_highgui.dylib,libopencv_imgproc.dylib和libopencv_video.dylib拖放到我的Xcode項目的Frameworks文件夾中,從/ opt/local/lib

+0

你期望的輸出?你是否驗證過'capFrame.data'是否不是'NULL'?此外,循環會經歷多少次迭代?正如所寫的,如果圖像被填充,您的代碼只會循環一次。 – Aurelius

+0

我正在檢查'capFrame.empty()'永遠不會變成真的。循環繼續,直到frameWaits = 1000,然後中斷。 – escapecharacter

回答

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

該代碼(功能上)與原始海報的非工作代碼相同。你有沒有使用不同的OpenCV版本? –