Color blob tracking with fixed white balance

Discussion related to "under the hood" OpenMV topics.
Azer
Posts: 3
Joined: Sat Feb 01, 2020 4:13 pm

Color blob tracking with fixed white balance

Postby Azer » Sat Feb 01, 2020 4:55 pm

Dear Sirs,
I have met following negative experience with H7 model.
My aim is tracking color blobs with repeatable result after cycling power. Following commands are used to activate camera:
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.set_auto_gain(False, 5.744431)
sensor.set_auto_whitebal(False,(-6.296998, -3.762909, 2.616725) )
sensor.set_auto_exposure(False, 6576)
sensor.skip_frames(time = 2000)

Result of tracking depends on camera directed to bright white surface or to dark surface at time of activation. If camera was directed to most bright surface in environment then white balance stays unchanged during session and image is dark at all time. If camera was directed to dark surface at time of activation then image seems brighter at initial period, but then can change to dark image if camera is turned to bright light, at following period image does not return to initial brightness. Together with reduced brightness of image several blobs disappear from detection. During both experiments gain, exposure and rgb_gain were inspected. Result is below.
gain = 5.459351
exposure = 6576
whitebal = (-6.438398, -3.658832, 2.766099)

These three values were same at both experiments and never changed together with image brightness. Gain and rgb_gain had never match the same values in set_auto_gain and set_auto_whitebal . If I change these values in set_auto_gain and set_auto_whitebal then inspected values appear to be different anyway.

Please advise how to stabilize measurements from jumping of white balance in image.

Sincerely Azer
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Color blob tracking with fixed white balance

Postby kwagyeman » Sat Feb 01, 2020 5:06 pm

You have to pass a keyword argument:

sensor.set_auto_gain(False, gain_db=5.744431)
sensor.set_auto_whitebal(False, rgb_gain_db=(-6.296998, -3.762909, 2.616725) )
sensor.set_auto_exposure(False, exposure_us=6576)
Nyamekye,
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Color blob tracking with fixed white balance

Postby kwagyeman » Sat Feb 01, 2020 5:12 pm

This seems to work:

Code: Select all

# Hello World Example
#
# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 1000)
sensor.set_auto_gain(False, 5.744431)
sensor.set_auto_whitebal(False,(-6.296998, -3.762909, 2.616725) )
sensor.set_auto_exposure(False, 6576)
clock = time.clock()                # Create a clock object to track the FPS.

while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    print(clock.fps(), sensor.get_gain_db(), sensor.get_rgb_gain_db(), sensor.get_exposure_us())              # Note: OpenMV Cam runs about half as fast when connected
                                    # to the IDE. The FPS should increase once disconnected.
Note that the camera might ignore you if you turn the auto gain methods off immediately before waiting a bit. Always wait a bit for the camera to stabilize. The camera chips have a micro-processor on that that will ignore settings if they are busy sometimes.
Nyamekye,
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Color blob tracking with fixed white balance

Postby kwagyeman » Sat Feb 01, 2020 5:15 pm

The gains you gave me BTW seem to make the image blue. I would recommend pointing the camera at a scene that's not one color.
Nyamekye,
Azer
Posts: 3
Joined: Sat Feb 01, 2020 4:13 pm

Re: Color blob tracking with fixed white balance

Postby Azer » Sat Feb 01, 2020 6:08 pm

Dear Sir,

I have used your advice with keyword arguments and with sensor.skip_frames(time = 1000).
At least I have one positive result : brightness of image doesn't change during one session. Thank you for this.
Other important negative feature remains: brightness of surface where camera initially directed. If I keep camera covered at time of activation by hand then whole session image is bright. If I direct camera to light at time of activation then whole session image is dark. Inspected values of gain, exposure and rgb_gain are same in both sessions. Is there any method to equalize image brightness conditions depending on activation scene? I can believe that one of methods is to cover camera each time at activation by hand, but we understand that this is not perfect solution.

Sincerely, Azer
User avatar
kwagyeman
Posts: 4271
Joined: Sun May 24, 2015 2:10 pm

Re: Color blob tracking with fixed white balance

Postby kwagyeman » Sat Feb 01, 2020 6:33 pm

No need to do that. Just run the script without turning all the auto controls off and record the values. Once you do that then apply those new settings to the script I gave you above and you should be good.

As for the initial frames that come out of the camera, skip frames ignores those. They don't matter.
Nyamekye,

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 9 guests