mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Moved feature detection scripts into their own folders and added explict frame_skip value per Ibrahim's request. Finished working on snapshot and video recording scripts for next release. ... From CMUcam4 work I learned that people will just want examples that do "X" thing. So, in general, our examples should include a simple script showing off a feature and then a more complex script that does "X" where "X" is some app that a person would want. For example, we'll get reuqests for face tracking with servos, and movement detection with servos. So, instead of answering this question a million times with an example script we'll just have examples for all kinds of things people will want. Gotta automate dealing with help support at the end of the day...
52 lines
1.8 KiB
Python
52 lines
1.8 KiB
Python
# Snapshot on Face Detection Example
|
|
#
|
|
# Note: You will need an SD card to run this example.
|
|
#
|
|
# This example demonstrates using face tracking on your OpenMV Cam to take a
|
|
# picture.
|
|
|
|
import sensor, image, pyb
|
|
|
|
RED_LED_PIN = 1
|
|
BLUE_LED_PIN = 3
|
|
|
|
sensor.reset() # Initialize the camera sensor.
|
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
|
sensor.set_framesize(sensor.HQVGA) # or sensor.QQVGA (or others)
|
|
sensor.skip_frames(10) # Let new settings take affect.
|
|
|
|
# Load up a face detection HaarCascade. This is object that your OpenMV Cam
|
|
# can use to detect faces using the find_features() method below. Your OpenMV
|
|
# Cam has fontalface HaarCascade built-in. By default, all the stages of the
|
|
# HaarCascade are loaded. However, You can adjust the number of stages to speed
|
|
# up processing at the expense of accuracy. The frontalface HaarCascade has 25
|
|
# stages.
|
|
face_cascade = image.HaarCascade("frontalface", stages=25)
|
|
|
|
while(True):
|
|
|
|
pyb.LED(RED_LED_PIN).on()
|
|
print("About to start detecting faces...")
|
|
sensor.skip_frames(60) # Give the user time to get ready.
|
|
|
|
pyb.LED(RED_LED_PIN).off()
|
|
print("Now detecting faces!")
|
|
pyb.LED(BLUE_LED_PIN).on()
|
|
|
|
diff = 10 # We'll say we detected a face after 10 frames.
|
|
while(diff):
|
|
img = sensor.snapshot()
|
|
# Threshold can be between 0.0 and 1.0. A higher threshold results in a
|
|
# higher detection rate with more false positives. The scale value
|
|
# controls the matching scale allowing you to detect smaller faces.
|
|
faces = img.find_features(face_cascade, threshold=0.5, scale=1.5)
|
|
|
|
if faces:
|
|
diff -= 1
|
|
for r in faces:
|
|
img.draw_rectangle(r)
|
|
|
|
pyb.LED(BLUE_LED_PIN).off()
|
|
print("Face detected! Saving image...")
|
|
sensor.snapshot().save("snapshot-%d.jpg" % pyb.rng()) # Save Pic.
|