我正在尝试使用带有 c++ 的 opencv 4.1.0 从 Macbook pro 的内置摄像头中读取一些帧。下面是我的代码:
#include "opencv2/opencv.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <unistd.h>
using namespace cv;
using namespace std;
int main(int, char**) {
VideoCapture cap(0);
if(!cap.isOpened())
cerr<<"Error! unable to open camera!";
return -1;
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
Mat frame;
namedWindow("Live");
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
return 0;
}
打电话时
VideoCapture cap(0);
我得到的错误是:
testApp[11889:464240] +[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x7fff9f79cd50
[ERROR:0] VIDEOIO(AVFOUNDATION): raised unknown C++ exception!
我尝试用其他索引替换 0,但它们都不起作用。有谁知道发生了什么?