我正在尝试使用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 wont' capture from MacBook Pro iSight
编辑:我安装opencv的程序是:
$ sudo port selfupdate
$ sudo port install opencv
然后,我将libopencv_core.dylib,libopencv_highgui.dylib,libopencv_imgproc.dylib和libopencv_video.dylib拖到我的Xcode项目的Frameworks文件夹中,从/ opt / local / lib
答案 0 :(得分:2)
OpenCV 2.4.6已损坏,无法与iSight摄像头配合使用。所以安装2.4.5。我已经为此写了一个分步指南:http://accidentalprogramming.blogspot.ch/2013/10/opencv-installation-on-mac-os-x.html
答案 1 :(得分: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;
}
}