Ask Your Question

How to set/get camera properties on Mac OS X

asked 2019-01-24 09:18:14 -0500

updated 2019-10-30 16:06:33 -0500

berak gravatar image

I am using OpenCV3 on Mac OS X. I want to get/set camera properties. Whatever value I tryout it has no effect. I wrote a simple code to see which properties are available and tried this with different webcams I own. But I could not get any values from any of the cams.

  • Is there something wrong in my code?
  • Does the Mac OS X backend not support to get/set camera properties?
  • Which webcams are fully controllable?

The code you can get as attachment.

Thx and regards Alexander

// The code I am using
#include "opencv2/opencv.hpp" 
using namespace cv;
using namespace std;

int main(int argc, char** argv)
     // Start default camera
    VideoCapture video(0);

    float Brightness = video.get(CV_CAP_PROP_BRIGHTNESS);
    float Contrast   = video.get(CV_CAP_PROP_CONTRAST );
    float Saturation = video.get(CV_CAP_PROP_SATURATION);
    float Gain       = video.get(CV_CAP_PROP_GAIN);

    float Position = video.get(CV_CAP_PROP_POS_MSEC);
    float Width = video.get(CV_CAP_PROP_FRAME_WIDTH);
    float Height = video.get(CV_CAP_PROP_FRAME_HEIGHT);
    float Format = video.get(CV_CAP_PROP_FORMAT);

    double Hue = video.get(CV_CAP_PROP_HUE);
    double Exposure = video.get(CV_CAP_PROP_EXPOSURE);
    double Mode = video.get(CV_CAP_PROP_MODE);
    double fps = video.get(CV_CAP_PROP_FPS);

    cout<<"Brightness -------> "<<Brightness<<endl;
    cout<<"Contrast----------> "<<Contrast<<endl;
    cout<<"Saturation--------> "<<Saturation<<endl;
    cout<<"Gain--------------> "<<Gain<<endl;
    cout<<"Hue---------------> "<<Hue<<endl;
    cout<<"Exposure----------> "<<Exposure<<endl;
    cout<<"Mode--------------> "<<Mode<<endl;


    return 0;
edit retag flag offensive close merge delete



...and what are the results?

Your code looks fine. Can you give us more details about your setup? Did you compile OpenCV yourself? If yes, did you enable V4L? Did you have libv4l-dev package installed?

Can you grab images from the webcam?

kbarni gravatar imagekbarni ( 2019-01-24 13:36:06 -0500 )edit

..and what are the results? Brightness -------> 0 Contrast----------> 0 Saturation--------> 0 Gain--------------> 0 Hue---------------> 0 Exposure----------> 0 Mode--------------> 0 Position---------->0 Width------------->1280 Height------------>720 Format------------>16 Frames---------->29.97

Your code looks fine. Can you give us more details about your setup?

Mac OS X 10.14.2 Mojave

Did you compile OpenCV yourself? No I use "macports" Version 3.

If yes, did you enable V4L?

Is this available on Mac OS X?

Did you have libv4l-dev package installed?

I did not - if it is not set in macports.

Can you grab images from the webcam? Yes I can!

To be precise: I try to workout how to control camera parameters like Brightness, saturation Hue and others. I set values to th

ademmler gravatar imageademmler ( 2019-01-24 14:51:00 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2019-10-30 12:56:03 -0500

arpit7t gravatar image

updated 2019-10-30 15:43:21 -0500

In OpenCV- 4.1.2-dev, macOS camera capture is handled using avfoundation. Currently opencv only supports changing width, height and fps for macOS as can be found here

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-01-24 09:18:14 -0500

Seen: 303 times

Last updated: Oct 30 '19