openmv/usr/examples/08-Feature-Detection/blob_detection.py
Kwabena W. Agyeman 94bc225542 Moved examples arround.
Tried to emulate Arduino's 11 folders... I'd perfer to have all the
shield scripts in one folder... but, that might not make sense. I don't
really want one script per folder however. So, I might merge some more
stuff in the future. I have a grand idea here that will become evident as
I work though the examples.

Anyway, the current structure is not final. It will be in flux for a
little while.

As for Git History, folder history is the best we're going to get. Git
and GitHub don't seem to deal with moves too well.
2016-03-30 21:30:11 -04:00

46 lines
915 B
Python

import sensor, time, pyb
led_r = pyb.LED(1)
led_g = pyb.LED(2)
led_b = pyb.LED(3)
sensor.reset()
sensor.set_contrast(2)
sensor.set_framesize(sensor.QCIF)
sensor.set_pixformat(sensor.RGB565)
clock = time.clock()
while (True):
clock.tick()
# Take snapshot
image = sensor.snapshot()
# Threshold image with RGB
binary = image.threshold([(255, 0, 0),
(0, 255, 0),
(0, 0, 255)], 80)
# Image closing
binary.dilate(3)
binary.erode(3)
# Detect blobs in image
blobs = binary.find_blobs()
led_r.off()
led_g.off()
led_b.off()
# Draw rectangles around detected blobs
for r in blobs:
if r[5]==1:
led_r.on()
if r[5]==2:
led_g.on()
if r[5]==3:
led_b.on()
image.draw_rectangle(r[0:4])
time.sleep(50)
print(clock.fps())