diff --git a/Code/OpenMV Code/find_circles_1.py b/Code/OpenMV Code/find_circles_1.py new file mode 100644 index 0000000000000000000000000000000000000000..b5cdc91584504448a4a02870d6ff20fe856f2728 --- /dev/null +++ b/Code/OpenMV Code/find_circles_1.py @@ -0,0 +1,54 @@ +# Find Circles Example +# +# This example shows off how to find circles in the image using the Hough +# Transform. https://en.wikipedia.org/wiki/Circle_Hough_Transform +# +# Note that the find_circles() method will only find circles which are completely +# inside of the image. Circles which go outside of the image/roi are ignored... + +import sensor, image, time, pyb +ir_led = pyb.LED(4) +red_led = pyb.LED(1) +b_led = pyb.LED(2) +g_led = pyb.LED(3) +ir_led.off() +ir_led.on() +red_led.off() +#red_led.on() + +sensor.reset() +sensor.set_pixformat(sensor.RGB565) # grayscale is faster +sensor.set_framesize(sensor.QVGA) +sensor.skip_frames(time = 2000) +sensor.set_auto_gain(False) # must turn this off to prevent image washout... +sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... +sensor.set_auto_exposure(False, 10000) +clock = time.clock() + +while(True): + clock.tick() + ir_led.on() + #red_led.on() + #b_led.on() + #g_led.on() + img = sensor.snapshot().lens_corr(1.8) + + # Circle objects have four values: x, y, r (radius), and magnitude. The + # magnitude is the strength of the detection of the circle. Higher is + # better... + + # `threshold` controls how many circles are found. Increase its value + # to decrease the number of circles detected... + + # `x_margin`, `y_margin`, and `r_margin` control the merging of similar + # circles in the x, y, and r (radius) directions. + + # r_min, r_max, and r_step control what radiuses of circles are tested. + # Shrinking the number of tested circle radiuses yields a big performance boost. + + for c in img.find_circles(threshold = 2000, x_margin = 10, y_margin = 10, r_margin = 10, + r_min = 2, r_max = 100, r_step = 2): + img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) + print(c) + + print("FPS %f" % clock.fps()) diff --git a/Code/OpenMV Code/square_tracking.py b/Code/OpenMV Code/square_tracking.py new file mode 100644 index 0000000000000000000000000000000000000000..942c66bbb6c56b44819c0ca33580e94631f83918 --- /dev/null +++ b/Code/OpenMV Code/square_tracking.py @@ -0,0 +1,45 @@ +# Find Rects Example +# +# This example shows off how to find rectangles in the image using the quad threshold +# detection code from our April Tags code. The quad threshold detection algorithm +# detects rectangles in an extremely robust way and is much better than Hough +# Transform based methods. For example, it can still detect rectangles even when lens +# distortion causes those rectangles to look bent. Rounded rectangles are no problem! +# (But, given this the code will also detect small radius circles too)... + +import sensor, image, time, pyb +ir_led = pyb.LED(4) +red_led = pyb.LED(1) +b_led = pyb.LED(2) +g_led = pyb.LED(3) +ir_led.off() +ir_led.on() +red_led.off() +#red_led.on() + +sensor.reset() +sensor.set_pixformat(sensor.RGB565) # grayscale is faster (160x120 max on OpenMV-M7) +sensor.set_framesize(sensor.QVGA) +sensor.skip_frames(time = 2000) +sensor.set_auto_gain(False) # must turn this off to prevent image washout... +sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... +sensor.set_auto_exposure(False, 25000) +clock = time.clock() + +while(True): + ir_led.on() + #red_led.on() + #b_led.on() + #g_led.on() + img = sensor.snapshot() + + # `threshold` below should be set to a high enough value to filter out noise + # rectangles detected in the image which have low edge magnitudes. Rectangles + # have larger edge magnitudes the larger and more contrasty they are... + + for r in img.find_rects(threshold = 5000): + #img.draw_rectangle(r.rect(), color = (255, 0, 0)) + #for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) + print(r) + + print("FPS %f" % clock.fps())