Reputation: 43
I'm trying to read some frames from the built-in camera of a Macbook pro using opencv 4.1.0 with c++. Below is the code I have:
#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;
}
When calling
VideoCapture cap(0);
the error I'm getting is:
testApp[11889:464240] +[AVCaptureDevice authorizationStatusForMediaType:]: unrecognized selector sent to class 0x7fff9f79cd50
[ERROR:0] VIDEOIO(AVFOUNDATION): raised unknown C++ exception!
I tried replacing 0 with other indices, but none of them work. Anyone know what is going on?
Upvotes: 1
Views: 850
Reputation: 33
I had the same issue but in python. I wanted to access the webcam and capture images, but continued to get this error. What solved my problem was a simple SMC reset of the macbook.
Upvotes: 0
Reputation: 11
What version of macOS are you running on? I had the exact same issue but in Java. I solved it today by upgrading my OS from High Sierra to Mojave version 10.14 and updating the Xcode command line tools in the terminal using xcode-select --install
.
I think the reason we got this problem is that Xcode command line tools - which provides the api (AVFoundation) to access camera on macOS and ios - was too old and therefore not compatible with the newly released OpenCV4.1.0. So my suggestion would be try to update your Xcode command line tools. In my case, I needed to upgrade my OS in order to get a newer version of it.
Upvotes: 1