2011-01-11 113 views
3

我無法使用以下OpenCV代碼從我的攝像頭捕獲圖像。OpenCV無法從isight攝像頭捕獲圖像

該代碼可以顯示來自本地AVI文件或視頻設備的圖像。它在「test.avi」文件中工作正常。

當我做我的使用默認的網絡攝像頭(CvCapture *捕獲= 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
  • 攝像頭iSight攝像頭
  • 的Macbook操作系統WIN7 32
  • VS2008
+0

我有相同的問題,幾乎相同的設置(WIN7 64)。我試過建設與opencv和QT不支持,但沒有任何工程。 – mwahab 2011-01-24 19:13:28

回答

1

你嘗試從opencv page的例子?

#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)。如果它不起作用,某種錯誤信息會有幫助。

+0

感謝您reply.The問題尚未解決。當我檢查「框架」,行和clos是正確的(480 * 640)。我不知道這個「框架」應該是什麼樣子。我有這個框架的截圖,你可以在這裏找到http://dusijun.wordpress.com/2011/01/11/opencv-unable-to-capture-image-from-isight-webcam/ image 3 – 2011-01-11 19:33:39

+0

網絡攝像頭與其他程序一起工作?可能只是一個驅動程序問題。 – etarion 2011-01-12 13:32:10

-1

你爲什麼不嘗試

capture=cvCaptureFromCam(0); 

我想這可能工作。

讓我知道wheather其工作與否。

3

我工作的OpenCV 2.3 MacBook Pro的2012年中,我有Isight凸輪的問題。不知怎的,我設法使它通過簡單地調整Cvcapture的參數,調整幀的寬度和高度上OpenCV的工作:

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

您還可以更改這些數字的幀的寬度和高度你想要的。

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