Tough to get exposure correct

Discussion related to "under the hood" OpenMV topics.
Posts: 91
Joined: Thu May 30, 2019 2:12 pm
Location: Ottawa, Canada

Tough to get exposure correct

Postby ScottM » Thu Jul 04, 2019 10:51 am

I'm using the QRCode sample, modified slightly, to read a large QR Code. The problem I'm having is how difficult it is to get the exposure right so that the code can be read. Ideally, I want to use a properly tuned auto exposure, because I'm sure that the lighting conditions will change in my lab over the course of a day. The sun hits the windows for part of the day. I tried turning off autoexposure and setting things manually, but it didn't work the way I thought it should.

Here is my code. You can see in the images that the QR Code is overexposed and the histogram shows it. Using manual exposure settings is only good if the environment is tightly controlled. I need a better autoexposure.

Code: Select all

import sensor, image, time

sensor.set_windowing((240, 240))      # look at center 240x240 pixels of the VGA resolution.
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)           # must turn this off to prevent image washout...
#sensor.set_brightness(0)              # range 0-31
#sensor.set_saturation(0)              # range -3 to 3
#sensor.set_gainceiling(2)             # 2,4,8,16,32,64,128
#sensor.set_contrast(2)                # range -3 to 3
clock = time.clock()

    img = sensor.snapshot()
    for code in img.find_qrcodes():
        img.draw_rectangle(code.rect(), color = 127)
Find QR Code.jpg
Find QR Code.jpg (4.5 KiB) Viewed 4129 times
Posts: 3
Joined: Fri Aug 16, 2019 5:10 pm

Re: Tough to get exposure correct

Postby anacoda » Tue Aug 27, 2019 11:59 am

Hi, I'm having the same problem.
The code I currently have for changing the exposure is as follows:


Code: Select all

ExpStep = 200
CurExp = 1000
MinBrt = 20
MaxBrt = 35
MinExp = 10
MaxExp = 60000

KP_High = 10
KP_Low = 100
And in the loop:

Code: Select all

sensor.set_auto_exposure(False, CurExp)

img = sensor.snapshot()
curStats = img.get_statistics()
CurBrt = curStats.l_mean()

if(CurBrt > MaxBrt):
    ErrHigh = CurBrt - MaxBrt
    ExpStep = KP_High * ErrHigh
    CurExp = max(CurExp - ExpStep, MinExp)
elif(CurBrt < MinBrt):
    ErrLow = MinBrt - CurBrt
    ExpStep = KP_Low * ErrLow
    CurExp = min(CurExp + ExpStep, MaxExp)
It kind of works but it's quite unreliable. Any suggestions?


User avatar
Posts: 4108
Joined: Sun May 24, 2015 2:10 pm

Re: Tough to get exposure correct

Postby kwagyeman » Tue Aug 27, 2019 2:13 pm

Hi, I made the camera driver better recently in the latest firmware about to come out. What boards do you have? I can upload the latest firmware for them here.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 6 guests