VideoCapture won't open camera on osx [closed]
I have a MacBook with a built in camera. When I try to open device 0 with VideoCapture, isOpen()
always returns false.
My OpenCV lib is compiled from source. Build options are largely default, with the exception that I enabled a few extra WITH_* flags (qt, for example). I am compiling on the command line, not with XCode.
- How do I troubleshoot why VideoCapture fails to open?
- How do I inspect available devices and their status?
- What is necessary in building opencv (or my own project) to ensure that video capture support is enabled?
- What might cause VideoCapture to fail?
I'm using the video capture example verbatim:
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) { // check if we succeeded
std::cout << "no capture device :(\n";
return -1;
}
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, COLOR_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
I remember having to put this for my Macbooks iSight camera to open properly, don't ask me how I figured this out..
try some other cam index as
VideoCapture cap(i)
withi: 0..n