How to set Contrast and Saturation parameters on DMM 37UX226-ML camera


I have set up an OpenCV module to connect to my USB Logitech camera.
Controlling the parameters of the camera works just fine with my Logitech camera, I’m able to change brightness, contrast, saturation, exposure and gain,

Then I switched to my DMM 37UX226-ML camera, I cat still change the brightness, exposure and gain parameters, but I can’t change the contrast and saturation, when I run the camera.set function for them it returns False.

Does anyone have any idea how can I change my contrast and saturation for my DMM camera ?

And in case my camera doesn’t support it, is there a way to change the contrast and the saturation of a given frame using cv2 functions ?

here’s the working code for the Logitech camera, but not for the DMM camera:

import cv2
width = 1920
height = 1080
camera = cv2.VideoCapture(0)
camera.set(3, width)
camera.set(4, height)

camera_properties = {
    'width' : cv2.CAP_PROP_FRAME_WIDTH,
    'height' : cv2.CAP_PROP_FRAME_HEIGHT,
    'brightness' : cv2.CAP_PROP_BRIGHTNESS,         
    'contrast' : cv2.CAP_PROP_CONTRAST,             
    'saturation' : cv2.CAP_PROP_SATURATION,         
    'gain' : cv2.CAP_PROP_GAIN,                      
    'exposure' : cv2.CAP_PROP_EXPOSURE,
    'focus' : cv2.CAP_PROP_FOCUS

               print(camera.set(cv2.CAP_PROP_AUTOFOCUS, 0)) # disable auto focus
print(camera.set(cv2.CAP_PROP_AUTO_EXPOSURE, 0.75)) # disable auto exposure

def set_camera_property(cam_property, value):
    global camera
    if cam_property == "exposure":
        value = 2 ** int(value)
    return_value = camera.set(camera_properties[cam_property], int(value)) 
    print("return value: " + str(return_value))


I don’t know this particular camera, but contrast and saturation are not camera parameters (like exposure for example). They are always set in post processing, even if this is performed in camera.
But you can do this post-processing yourself.

imghsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV).astype("float32")
(h, s, v) = cv2.split(imghsv)
s = s * satadj
s = np.clip(s,0,255)
v = (v - 128) * contrastadj + 128
v = np.clip(v,0,255)
imghsv = cv2.merge([h,s,v])
imgrgb = cv2.cvtColor(imghsv.astype("uint8"), cv2.COLOR_HSV2BGR)
1 Like

Thank you for your response.

It’s working, but sadly it takes on average 4 seconds to calculate it because my image’s resolution is 4000x3000, do you think there is a faster version of this ?

And one more thing, I can’t stop the auto gain of this camera, I have the values available for the CAP_PROP_AUTO_EXPOSURE for my camera, it only takes the values: [1.0, 1.5) , [2.0, 2.5) and [3.0, 3.5) it doesn’t take any other values, for exmaple I can set it to 1.0, 1.15, 2.49, 3.33 but I can’t set it to 3.5, 2.55, 0.25.

Do you have any idea how to set the CAP_PROP_GAIN to a constant value ?

Thanks again.

That’s the working contrast and saturation on the image.

By the way, a few more things:

  • The DMM 37UX226-ML is a monochrome camera!!! So there’s no saturation parameter!
  • For faster processing keep the images in 8 bit monochrome (CV_8U) instead of converting it to RGB (CV_8UC3)
  • General rule for industrial cameras (especially if you need control over the parameters): always use the provided SDK. OpenCV is not a camera management library. It tries to provide some control over the parameters using generic methods, but it isn’t something reliable. The SDK gives full control over literally hundreds of camera parameters with full documentation - so you don’t have to guess if a parameter is supported and what the hell does it mean an auto exposure of 3.33…
1 Like

Thank you again for your help.

I will contact the support of the-imaging-source.