Hi!
I am currently working on a way to have OpenMV track a face, and follow it using a pan/tilt servo kit. So far, I have tried to have it follow the crosses drawn by the script onto the face,
but the servo just moves back and forth, and cannot actually follow it.
import sensor, time, image
from pyb import Servo
# Reset sensor
sensor.reset()
# Sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.__write_reg(0x0C, sensor.__read_reg(0x0C) | (1 << 7)) #Flips Camera
s1 = Servo(1) # servo on position 1 (PB15, VIN, GND)
# Load Haar Cascade
# By default this will use all stages, lower satges is faster but less accurate.
face_cascade = image.HaarCascade("frontalface", stages=16)
print(face_cascade)
def find_face():
for i in range(0, 30):
img = sensor.snapshot()
while (True):
img = sensor.snapshot()
objects = img.find_features(face_cascade, threshold=0.65, scale=1.65)
for r in objects:
img.draw_rectangle(r)
try:
kpts1 = img.find_keypoints(threshold=32, normalized=False, roi=objects[0])
except:
continue
if kpts1:
img.draw_keypoints(kpts1)
time.sleep(100)
return kpts1
kpts1 = find_face()
clock = time.clock()
while (True):
clock.tick()
img = sensor.snapshot()
try:
kpts2 = img.find_keypoints(threshold=32, normalized=False)
except:
continue
if (kpts2==None):
continue
c=img.match_keypoints(kpts1, kpts2, 70)
if (c):
l=10
img.draw_line((c[0]-l, c[1], c[0]+l, c[1]))
img.draw_line((c[0], c[1]-l, c[0], c[1]+l))
s1.angle(c[0], 500)
time.sleep(20)
print (clock.fps())
Does anyone have any suggestions as to how to have OpenMV relay face marker position to servo position? Thanks in advance!