views:

605

answers:

2

I am building an application using OpenCV that uses the webcam and runs some vision algorithms. I would like to make this application available on the internet after I am done, but I am concerned about the vast differences in camera settings on every computer, and I am worried that the algorithm may break if the settings are too different from mine.

Is there any way, after capturing the frame, to post process it and make sure that the contrast is X, brightness is Y, and saturation is Z? I think the Camera settings themselves can not be changed from code directly using the current OpenCV Python bindings.

Would anyone be able to tell me about how I could calculate some of these parameters from the image and adjust them appropriately using OpenCV?

+1  A: 

You can post process your image in openCV several ways.

To set the contrast you can use equalizeHist function.

To set brightness and saturation you should first convert the image to HSV color space with cvtColor. Then you can modify the saturation and the value (brightness) to an appropriate value by directly accessing each image pixel.

rics
A: 

I'm kind of struggling with the same issue. Here's a piece of code that strips all value (brightness) information from an image making it perhaps a bit more stable in situations where the amount of light changes a lot. You can of course adjust any of the other parameters as well:

    // img is an rgb image
    cvCvtColor(img, img, CV_RGB2HSV);
    for( int y=0; y<img->height; y++ ) {
        uchar* ptr = (uchar*) (
            img->imageData + y * img->widthStep
        );
        for( int x=0; x<img->width; x++ ) {
            ptr[3*x+2] = 255; // maxes the value,
            // use +1 for saturation, +0 for hue
        }
    }

    // convert back for displaying
    cvCvtColor(img, img, CV_HSV2RGB);
luopio