Two issues: White balance/blob and Flashing code into ROM

Good morning,

I have been testing the color blob function with my system and have used snapshot to figure out which thresholds to use with my bright colors. I’m quickly realizing that I’ll turn on the camera and look at the system and sometimes the thresholds work perfectly… while other times the camera doesn’t detect the colors at all. It’s quite frustrating. Why is it that the thresholds are not holding up after power cycling sometimes? And furthermore, when I look at the frames being displayed on OpenMV IDE, the camera will have a red or green hue to the entire image sometimes (the two thresholds I’m using are green and red), so why is this happening?

As another concern, I have flashed in the LED example and tried to power the camera without my usb power (just a 5 volt battery across the VIN and GND, as there is a 3v3 regulator on the board), but the LEDs are not flashing the correct pattern. So why can’t I get the code to stay on the board after closing the IDE?

Here is my code for the first problem by the way:

# First try at programming OpenMV to do what I need

import sensor, image, time, math, pyb, cpufreq

# experiment with upping the CPU speed

cpufreq.set_frequency(480) # maxed to 480 MHz

# NOTE: blob.code() will return a number that corresponds to which threshold found for specific blob
# ie, blob.code() = 1 for green, 2 for 'light pink'
thresholds =	[(58, 100, -128, -40, 22, 61),#(75, 100, -80, -7, 19, 78),#(14, 100, 14, -48, 35, 127),#(59, 12, -13, -128, 12, 98),#(99, 32, -23, -102, 2, 91), # green
                (54, 65, 29, 127, -31, 2)]#(52, 74, 36, 127, -17, 13)]#(49, 77, 65, 98, 25, -121)]#(99, 37, 127, 46, -83, 127)] # light pink

# (0, 73, -69, -13, -67, 49) green
# this seems to be a standard down here

# initilize the camera sensor

# sets the pixel format (GRAYSCALE 8-bits per pixel, RGB565 16-bits per pixel, BAYER 8-bits per pixel bayer pattern)

# VGA = 640x480, QVGA = 320x240, QQVGA = 160x120
# QQVGA --> 53 mS (just using snapshot)
# HQVGA --> 53 mS (^, but looks like dropping frames?)
# QVGA --> 53-4 mS (^, mmight be dropping frames?)

# sets a resolution inside
# for VGA
#sensor.set_windowing([500,240]) # (x,y,w,h) or just (w,h) and is centered

# sensor.skip_frames([n,time])
# skip_frames(10) to skip 10 frames --> call this function after changing cam settings
# alternatively, pass keyword 'time' time= 2000 to skip 2000 milliseconds
sensor.skip_frames(time = 2000)

# this must be turned off for color tracking

# must be turned off for color tracking

# returns a clock object
# Use to keep track of time
clock = time.clock()

#counter = 0

#def tick(tim, counter):
#    if(counter == 100000000):
#        counter = 0
#    return counter + 1

# create a timer object
# use internal timer 4, and counter interrupts every 50 ms
#tim = pyb.Timer(4)
#tim.init(freq = 20)
#tim.init(prescaler = 83, period = 99)

# initialize two previous x/theta values to determine dot's
prev_x = 0
prev_y = 0
# initialize the 4 transmission variables
x = 0
x_dot = 0
theta = 0
theta_dot = 0
# initialize state variables
state = 0
prev_state = 0

start = pyb.millis()
while True:
    if(pyb.elapsed_millis(start) > 20): # looks like it works right
        start = pyb.millis()
        img = sensor.snapshot()
        for blob in img.find_blobs(thresholds, pixels_threshold=200, area_threshold=200):
            # These values depend on the blob not being circular - otherwise they will be shaky.
            if blob.elongation() > 0.5:
                img.draw_edges(blob.min_corners(), color=(255,0,0))
                img.draw_line(blob.major_axis_line(), color=(0,255,0))
                img.draw_line(blob.minor_axis_line(), color=(0,0,255))
            # These values are stable all the time.
            # Note - the blob rotation is unique to 0-180 only.
            img.draw_keypoints([(,, int(math.degrees(blob.rotation())))], size=20)
            if(blob.code() == 1): # this will be the wheel
                print("Green: (cx,cy) = ",,



So I actually figured out the persistent ROM writing, but I would still like assistance on getting my thresholds to stay consistent. The only solution I could think of was adding 8 thresholds for the pink color I’m tracking and 8 for the green. Only concern there would be tracking more than the two points I need to track. Maybe there’s a way of merging the thresholds and changing my pixel area requirements, but I’m uncertain.

Hi, you’re running into the fact that the camera auto white balances the image based on what is sees. If the image is filled with one color when it turns on it will white balance the image to make that color combo look white.

So, if possible, you should turn off white balance immediately before even skip frames happens. If you don’t the camera changes the color settings to what it sees in front of it.

I probably should just edit the scripts so white balance is turned off always for color tracking. Just note that the issue with not letting white balance run is that the camera image will look a lot less nice when the lighting in the room isn’t white.