VideoCapture won't open camera on osx [closed]

asked 2015-11-03 01:35:00 -0600

tbabb gravatar image

updated 2015-11-03 01:35:40 -0600

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;
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-27 10:06:43.921715

Comments

I remember having to put this for my Macbooks iSight camera to open properly, don't ask me how I figured this out..

// set video capture properties for MacBook' iSight camera
videoCapture.set(CV_CAP_PROP_FRAME_WIDTH, 500);
videoCapture.set(CV_CAP_PROP_FRAME_HEIGHT, 600);
boaz001 gravatar imageboaz001 ( 2015-11-03 07:30:23 -0600 )edit

try some other cam index as VideoCapture cap(i) with i: 0..n

pklab gravatar imagepklab ( 2015-11-03 09:59:08 -0600 )edit