【发布时间】:2014-05-04 23:10:12
【问题描述】:
我正在使用 Macbook Air 2013 参加 OSX Mavericks。
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
int main()
{
cv::VideoCapture cap;
cap.open(0);
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***\n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(frame.empty()){
std::cerr<<"frame is empty"<<std::endl;
break;
}
cv::imshow("", frame);
cv::waitKey(10);
}
return 1;
}
相机正确初始化(isOpened 返回 true),但它不断返回空帧。但是,从文件而不是相机中检索帧可以正常工作。
此外,使用 C API 的 cvQueryFrame 似乎工作正常!
关于如何调试我的问题有什么想法吗?
编辑: 下面的代码似乎可以让相机正常工作。有人知道为什么吗?
#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/tracking.hpp>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap;
cap.open(0);
namedWindow("Window");
if( !cap.isOpened() )
{
std::cerr << "***Could not initialize capturing...***\n";
return -1;
}
cv::Mat frame;
while(1){
cap >> frame;
if(!(frame.empty())){
imshow("Window", frame);
}
waitKey(10);
}
return 1;
}
【问题讨论】:
-
对我来说没问题。你的相机在运行时打开成功了吗?
-
@herohuyongtao 好吧,我不确定。 cap.isOpened() 返回 true,但是我的相机灯没有打开。这说明什么?
-
您使用的是哪个 OpenCV 版本?视频通话时可以打开摄像头吗?
-
@herohuyongtao 我正在使用 OpenCV 2.4.9。当我进行视频通话时,我的摄像头工作正常。
-
看看this solution是否有帮助。
标签: c++ opencv osx-mavericks