Я пытаюсь прочитать некоторые кадры со встроенной камеры MacBook Pro, используя opencv 4.1.0 с c ++. Ниже приведен код, который у меня есть:
#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 другими индексами, но ни один из них не работает. Кто-нибудь знает, что происходит?