From 69d71a70152e191a9a27397b7c356e8536aa48ee Mon Sep 17 00:00:00 2001 From: "Kwabena W. Agyeman" Date: Sun, 3 Mar 2019 22:57:25 -0500 Subject: [PATCH] Add examples --- .../examples/28-Global-Shutter/high_fps.py | 29 +++++++++++++++++++ .../28-Global-Shutter/triggered_mode.py | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 scripts/examples/28-Global-Shutter/high_fps.py create mode 100644 scripts/examples/28-Global-Shutter/triggered_mode.py diff --git a/scripts/examples/28-Global-Shutter/high_fps.py b/scripts/examples/28-Global-Shutter/high_fps.py new file mode 100644 index 000000000..d2cf12ded --- /dev/null +++ b/scripts/examples/28-Global-Shutter/high_fps.py @@ -0,0 +1,29 @@ +# High FPS Example +# +# This example shows off how to make the frame rate of the global shutter camera extremely +# high. To do so you need to set the resolution to a low value such that pixel binning is +# activated on the camera and then reduce the maximum exposure time. +# +# When the resolution is 320x240 or less the camera reads out pixels 2x faster. When the +# resolution is 160x120 or less the camera reads out pixels 4x faster. This happens due +# to pixel binning which is automatically activated for you to increase the readout speed. +# +# While the readout speed may increase the camera must still expose the image for the request +# time so you will not get the maximum readout speed unless you reduce the exposure time too. +# This results in a dark image however so YOU NEED A LOT of lighting for high FPS. + +import sensor, image, time + +sensor.reset() # Reset and initialize the sensor. +sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE +sensor.set_framesize(sensor.QQVGA) # Set frame size to QQVGA (160x120) - make smaller to go faster +sensor.skip_frames(time = 2000) # Wait for settings take effect. +clock = time.clock() # Create a clock object to track the FPS. + +sensor.set_auto_exposure(True, exposure_us=5000) # make smaller to go faster + +while(True): + clock.tick() # Update the FPS clock. + img = sensor.snapshot() # Take a picture and return the image. + print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected + # to the IDE. The FPS should increase once disconnected. diff --git a/scripts/examples/28-Global-Shutter/triggered_mode.py b/scripts/examples/28-Global-Shutter/triggered_mode.py new file mode 100644 index 000000000..cbbec8ac7 --- /dev/null +++ b/scripts/examples/28-Global-Shutter/triggered_mode.py @@ -0,0 +1,29 @@ +# Global Shutter Triggered Mode Example +# +# This example shows off setting the global shutter camera into triggered mode. In triggered mode +# snapshot() controls EXACTLY when integration of the camera pixels start such that you can sync +# taking pictures to some external movement. Since the camera captures all pixels at the same time +# (as it is a global shutter camera versus a rolling shutter camera) movement in the image will +# only be captured for the integration time and not the integration time multipled by the number +# of rows in the image. Additionally, sensor noise is reduced in triggered mode as the camera will +# not read out rows until after exposing which results in a higher quality image. +# +# That said, your maximum frame rate will be reduced by 2 to 3 as frames are no longer generated +# continously by the camera and because you have to wait for the integration to finish before +# readout of the frame. + +import sensor, image, time + +sensor.reset() # Reset and initialize the sensor. +sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to GRAYSCALE +sensor.set_framesize(sensor.VGA) # Set frame size to VGA (640x480) +sensor.skip_frames(time = 2000) # Wait for settings take effect. +clock = time.clock() # Create a clock object to track the FPS. + +sensor.mt9v034_set_triggered_mode(True) + +while(True): + clock.tick() # Update the FPS clock. + img = sensor.snapshot() # Take a picture and return the image. + print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected + # to the IDE. The FPS should increase once disconnected.