捕捉視頻我在OSX小牛一臺MacBook Air 2013從相機
#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
@herohuyongtao嗯,我不確定。 cap.isOpened()返回true,但是我的相機指示燈未打開。這是什麼意思? – dfg
你使用了哪個OpenCV版本?當你有視頻通話時,你的相機能打開嗎? – herohuyongtao