mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
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.
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
# Motion Detection Example:
|
|
#
|
|
# This example demonstrates using frame differencing with your OpenMV Cam to do
|
|
# motion detection. After motion is detected your OpenMV Cam will take picture.
|
|
|
|
import os, pyb, sensor, image, time
|
|
|
|
if not "temp" in os.listdir(): os.mkdir("temp") # Make a temp directory
|
|
|
|
sensor.reset()
|
|
sensor.set_framesize(sensor.QVGA)
|
|
|
|
while(True):
|
|
sensor.set_pixformat(sensor.GRAYSCALE) # Grayscale is much faster than RGB.
|
|
|
|
# Warm up the cam
|
|
for i in range(10):
|
|
sensor.snapshot()
|
|
|
|
for i in [5, 4, 3, 2, 1]:
|
|
print("Saving background in... %d" % i)
|
|
time.sleep(1000)
|
|
|
|
print("Saving background...")
|
|
sensor.snapshot().save("temp/bg.bmp")
|
|
|
|
diff = 30 # wait 30 snapshot before taking picture
|
|
while(diff):
|
|
img = sensor.snapshot()
|
|
img.difference("temp/bg.bmp")
|
|
img.binary([(32, 255)])
|
|
sum, x, y = img.centroid()
|
|
if sum > 100: # 100 pixels detected
|
|
img.draw_cross(x, y, color = 127)
|
|
diff -= 1
|
|
|
|
sensor.set_pixformat(sensor.RGB565)
|
|
# Warm up the cam
|
|
for i in range(10):
|
|
sensor.snapshot()
|
|
sensor.snapshot().save("temp/movement-%d" % pyb.rng()) # Save movement
|