mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Update ImageIO examples
This commit is contained in:
parent
acf450caa3
commit
93bbac0bf3
@ -0,0 +1,34 @@
|
||||
# Image Memory Stream I/O Example
|
||||
#
|
||||
# This example shows how to use the ImageIO stream to record frames in memory and play them back.
|
||||
# Note: While this should work on any board, the board should have an SDRAM to be of any use.
|
||||
import sensor, image, time
|
||||
|
||||
# Number of frames to pre-allocate and record
|
||||
N_FRAMES = 500
|
||||
|
||||
sensor.reset()
|
||||
sensor.set_pixformat(sensor.RGB565)
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
|
||||
# This frame size must match the image size passed to ImageIO
|
||||
sensor.set_windowing((120, 120))
|
||||
sensor.skip_frames(time = 2000)
|
||||
|
||||
clock = time.clock()
|
||||
|
||||
# Write to memory stream
|
||||
stream = image.ImageIO((120, 120, 2), N_FRAMES)
|
||||
|
||||
for i in range(0, N_FRAMES):
|
||||
clock.tick()
|
||||
stream.write(sensor.snapshot())
|
||||
print(clock.fps())
|
||||
|
||||
while (True):
|
||||
# Rewind stream and play back at 100FPS
|
||||
stream.seek(0)
|
||||
for i in range(0, N_FRAMES):
|
||||
img = stream.read(copy_to_fb=True)
|
||||
# Do machine vision algorithms on the image here.
|
||||
time.sleep_ms(10)
|
||||
@ -18,11 +18,15 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.skip_frames(time = 2000)
|
||||
clock = time.clock()
|
||||
|
||||
img_reader = None if snapshot_source else image.ImageReader("/stream.bin")
|
||||
stream = None
|
||||
if snapshot_source == False:
|
||||
stream = image.ImageIO("/stream.bin", "r")
|
||||
|
||||
while(True):
|
||||
clock.tick()
|
||||
img = sensor.snapshot() if snapshot_source else img_reader.next_frame(copy_to_fb=True, loop=True, pause=True)
|
||||
if snapshot_source:
|
||||
img = sensor.snapshot()
|
||||
else:
|
||||
img = stream.read(copy_to_fb=True, loop=True, pause=True)
|
||||
# Do machine vision algorithms on the image here.
|
||||
|
||||
print(clock.fps())
|
||||
@ -16,28 +16,21 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.skip_frames(time = 2000)
|
||||
clock = time.clock()
|
||||
|
||||
img_writer = image.ImageWriter("/stream.bin")
|
||||
stream = image.ImageIO("/stream.bin", "w")
|
||||
|
||||
# Red LED on means we are capturing frames.
|
||||
red_led = pyb.LED(1)
|
||||
red_led.on()
|
||||
pyb.LED(1).on()
|
||||
|
||||
start = pyb.millis()
|
||||
while pyb.elapsed_millis(start) < record_time:
|
||||
clock.tick()
|
||||
img = sensor.snapshot()
|
||||
# Modify the image if you feel like here...
|
||||
|
||||
img_writer.add_frame(img)
|
||||
stream.write(img)
|
||||
print(clock.fps())
|
||||
|
||||
img_writer.close()
|
||||
stream.close()
|
||||
|
||||
# Blue LED on means we are done.
|
||||
red_led.off()
|
||||
blue_led = pyb.LED(3)
|
||||
blue_led.on()
|
||||
|
||||
print("Done")
|
||||
while(True):
|
||||
pyb.wfi()
|
||||
pyb.LED(1).off()
|
||||
pyb.LED(3).on()
|
||||
34
scripts/examples/OpenMV/06-Video-Recording/imageio_memory.py
Normal file
34
scripts/examples/OpenMV/06-Video-Recording/imageio_memory.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Image Memory Stream I/O Example
|
||||
#
|
||||
# This example shows how to use the ImageIO stream to record frames in memory and play them back.
|
||||
# Note: While this should work on any board, the board should have an SDRAM to be of any use.
|
||||
import sensor, image, time
|
||||
|
||||
# Number of frames to pre-allocate and record
|
||||
N_FRAMES = 500
|
||||
|
||||
sensor.reset()
|
||||
sensor.set_pixformat(sensor.RGB565)
|
||||
sensor.set_framesize(sensor.QVGA)
|
||||
|
||||
# This frame size must match the image size passed to ImageIO
|
||||
sensor.set_windowing((120, 120))
|
||||
sensor.skip_frames(time = 2000)
|
||||
|
||||
clock = time.clock()
|
||||
|
||||
# Write to memory stream
|
||||
stream = image.ImageIO((120, 120, 2), N_FRAMES)
|
||||
|
||||
for i in range(0, N_FRAMES):
|
||||
clock.tick()
|
||||
stream.write(sensor.snapshot())
|
||||
print(clock.fps())
|
||||
|
||||
while (True):
|
||||
# Rewind stream and play back at 100FPS
|
||||
stream.seek(0)
|
||||
for i in range(0, N_FRAMES):
|
||||
img = stream.read(copy_to_fb=True)
|
||||
# Do machine vision algorithms on the image here.
|
||||
time.sleep_ms(10)
|
||||
@ -18,11 +18,15 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.skip_frames(time = 2000)
|
||||
clock = time.clock()
|
||||
|
||||
img_reader = None if snapshot_source else image.ImageReader("/stream.bin")
|
||||
stream = None
|
||||
if snapshot_source == False:
|
||||
stream = image.ImageIO("/stream.bin", "r")
|
||||
|
||||
while(True):
|
||||
clock.tick()
|
||||
img = sensor.snapshot() if snapshot_source else img_reader.next_frame(copy_to_fb=True, loop=True, pause=True)
|
||||
if snapshot_source:
|
||||
img = sensor.snapshot()
|
||||
else:
|
||||
img = stream.read(copy_to_fb=True, loop=True, pause=True)
|
||||
# Do machine vision algorithms on the image here.
|
||||
|
||||
print(clock.fps())
|
||||
@ -16,28 +16,21 @@ sensor.set_framesize(sensor.QQVGA)
|
||||
sensor.skip_frames(time = 2000)
|
||||
clock = time.clock()
|
||||
|
||||
img_writer = image.ImageWriter("/stream.bin")
|
||||
stream = image.ImageIO("/stream.bin", "w")
|
||||
|
||||
# Red LED on means we are capturing frames.
|
||||
red_led = pyb.LED(1)
|
||||
red_led.on()
|
||||
pyb.LED(1).on()
|
||||
|
||||
start = pyb.millis()
|
||||
while pyb.elapsed_millis(start) < record_time:
|
||||
clock.tick()
|
||||
img = sensor.snapshot()
|
||||
# Modify the image if you feel like here...
|
||||
|
||||
img_writer.add_frame(img)
|
||||
stream.write(img)
|
||||
print(clock.fps())
|
||||
|
||||
img_writer.close()
|
||||
stream.close()
|
||||
|
||||
# Blue LED on means we are done.
|
||||
red_led.off()
|
||||
blue_led = pyb.LED(3)
|
||||
blue_led.on()
|
||||
|
||||
print("Done")
|
||||
while(True):
|
||||
pyb.wfi()
|
||||
pyb.LED(1).off()
|
||||
pyb.LED(3).on()
|
||||
Loading…
Reference in New Issue
Block a user