Standardize camera input in OpenCV? (Contrast / Saturation / Brightness, etc.)

I am creating an application using OpenCV that uses a webcam and runs some vision algorithms. I would like to make this application available on the Internet after I have finished, but I am worried about the huge differences in the camera settings on each computer, and I am worried that the algorithm may break if the settings are too different from mine.

Is there a way, after capturing a frame, to publish it and make sure that the contrast is X, the brightness is Y, and the saturation is Z? I think that the camera settings themselves cannot be changed directly from the code using the current OpenCV Python bindings.

Can anyone tell me how I can calculate some of these parameters from an image and adjust them accordingly using OpenCV?

+3
source share
2 answers

You can send your image to openCV in several ways.

To set the contrast, you can use equalizeHist .

To set the brightness and saturation, you must first convert the image to HSV color space using cvtColor . Then you can change the saturation and value (brightness) to the corresponding value, directly referring to each pixel in the image.

+3
source

. , () , , , , . :

    // 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);
+2

Source: https://habr.com/ru/post/1743267/


All Articles