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:
Code: Select all
# 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 sensor.reset() # sets the pixel format (GRAYSCALE 8-bits per pixel, RGB565 16-bits per pixel, BAYER 8-bits per pixel bayer pattern) sensor.set_pixformat(sensor.RGB565) # 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?) sensor.set_framesize(sensor.QVGA) # 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 sensor.set_auto_gain(False) # must be turned off for color tracking sensor.set_auto_whitebal(False) # returns a clock object # Use to keep track of time clock = time.clock() #counter = 0 #def tick(tim, counter): # if(counter == 100000000): # counter = 0 #print(counter) # 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.callback(tick) #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 print(pyb.elapsed_millis(start)) 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. img.draw_rectangle(blob.rect()) img.draw_cross(blob.cx(), blob.cy()) # Note - the blob rotation is unique to 0-180 only. img.draw_keypoints([(blob.cx(), blob.cy(), int(math.degrees(blob.rotation())))], size=20) if(blob.code() == 1): # this will be the wheel print("Green: (cx,cy) = ", blob.cx(), blob.cy())