From 7f3b14ec0eff6cbaedd921b8fd8a6a7b790656c3 Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sat, 16 Oct 2021 12:29:13 -0700 Subject: [PATCH] Add event camera examples --- .../OpenMV/37-Event-Cameras/frogeye2020.py | 39 ++++++++++++++++ .../frogeye2020_with_tracking.py | 45 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 scripts/examples/OpenMV/37-Event-Cameras/frogeye2020.py create mode 100644 scripts/examples/OpenMV/37-Event-Cameras/frogeye2020_with_tracking.py diff --git a/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020.py b/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020.py new file mode 100644 index 000000000..445c0849a --- /dev/null +++ b/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020.py @@ -0,0 +1,39 @@ +# This example shows off using the frogeye2020 event camera. +# +# The frogeye2020 is a 320x240 event camera. There are two bits per pixel which show no motion, +# motion in one direction, or motion in another direction. The sensor runs at 50 FPS. + +import sensor, image, time + +sensor.reset() +sensor.set_pixformat(sensor.GRAYSCALE) +sensor.set_framesize(sensor.QVGA) + +palette = image.Image(1, 256, sensor.RGB565) + +for i in range(64): + palette.set_pixel(0, i, (0, 0, 0)) + +for i in range(64, 128): + palette.set_pixel(0, i, (255, 0, 0)) + +for i in range(128, 192): + palette.set_pixel(0, i, (0, 0, 255)) + +for i in range(192, 256): + palette.set_pixel(0, i, (0, 255, 0)) + +clock = time.clock() + +while(True): + clock.tick() + + img = sensor.snapshot() + # Handle sensor rotation. + img.assign(hmirror=True, vflip=True) + # Make pretty. + img.to_rainbow(color_palette=palette) + # Cleanup noise. + img.erode(1) + + print(clock.fps()) diff --git a/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020_with_tracking.py b/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020_with_tracking.py new file mode 100644 index 000000000..c373715dc --- /dev/null +++ b/scripts/examples/OpenMV/37-Event-Cameras/frogeye2020_with_tracking.py @@ -0,0 +1,45 @@ +# This example shows off using the frogeye2020 event camera with tracking. +# +# The frogeye2020 is a 320x240 event camera. There are two bits per pixel which show no motion, +# motion in one direction, or motion in another direction. The sensor runs at 50 FPS. + +import sensor, image, time + +sensor.reset() +sensor.set_pixformat(sensor.GRAYSCALE) +sensor.set_framesize(sensor.QVGA) + +palette = image.Image(1, 256, sensor.RGB565) + +for i in range(64): + palette.set_pixel(0, i, (0, 0, 0)) + +for i in range(64, 128): + palette.set_pixel(0, i, (255, 0, 0)) + +for i in range(128, 192): + palette.set_pixel(0, i, (0, 0, 255)) + +for i in range(192, 256): + palette.set_pixel(0, i, (0, 255, 0)) + +clock = time.clock() + +while(True): + clock.tick() + + img = sensor.snapshot() + # Handle sensor rotation. + img.assign(hmirror=True, vflip=True) + # Make pretty. + img.to_rainbow(color_palette=palette) + # Cleanup noise. + img.erode(1) + + blobs = img.find_blobs([(0, 0)], invert=True, + pixels_threshold=10, area_threshold=10, merge=False) + + for blob in blobs: + img.draw_rectangle(blob.rect(), color=(0, 255, 0)) + + print(clock.fps())