使用 Opencv 从 Macbook Pro iSight 捕获
Capturing from Macbook Pro iSight with Opencv
我正在尝试使用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.isOpen 始终返回 true。
编辑:似乎其他人遇到了这个问题:OpenCV不会从MacBook Pro iSight捕获
编辑:我安装opencv的过程是:
$ 须藤端口自我更新
$ sudo port install opencv
然后,我将 libopencv_core.dylib、libopencv_highgui.dylib、libopencv_imgproc.dylib 和 libopencv_video.dylib 从/opt/local/lib 拖到 Xcode 项目的 Frameworks 文件夹中。
OpenCV 2.4.6 已损坏,无法与 iSight 相机配合使用。因此,请改为安装 2.4.5。我为此编写了一个分步指南:http://accidentalprogramming.blogspot.ch/2013/10/opencv-installation-on-mac-os-x.html
我使用以下代码得到了它:
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;
}
}
相关文章:
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 当类定义不可见时捕获异常
- 当系统的卷被修改时,如何修改WASAPI环回捕获卷
- 在 lambda 捕获中声明的变量的类型推导
- RtlCaptureStackBackTrace未捕获任何帧
- 如何在Qt中取消捕获字符串
- 当我在其中一个线程执行中(在activemq-cpp中)捕获到特定值时,我如何终止/停止所有其他线程
- 如何将strftime中的格式错误作为异常捕获
- 在Linux下捕获SIGKILL的C++程序
- 按值捕获引用时出现非常量
- 捕获lambda中的std::数组
- 由cin中的字符串中未捕获空白引起的分割错误
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 捕获标准输出以压缩并使用 CTRL-C 中断会给出损坏的 zip 文件
- 在 Windows 8/10 技术中完全实时的屏幕捕获,没有延迟
- 当简单捕获中的标识符显示为参数的声明符 ID 时,没有编译器诊断
- SDL_PollEvent() 无法捕获类函数内部SDL_QUIT?
- 在信号处理程序中捕获C++未处理的异常并恢复应用程序
- 使用 Opencv 从 Macbook Pro iSight 捕获
- 尝试捕获默认 iSight 摄像头时出现 OpenCV 崩溃