import sensor, time, image, pyb, uos
from pyb import Pin
from ir_remote import IRrecv
ir = IRrecv(Pin("P6", Pin.IN))
ls = []
while(True):
key = ir.read()
if key:
if key != 'None':
if key == '#':#*******
d=ls
ls = []
break
else:
#print(type(key))
ls.append(key)
print(key)
uos.mkdir("singtong/%s"%(d))
RED_LED_PIN = 1
BLUE_LED_PIN = 3
sensor.reset()
sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.HQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
face_cascade = image.HaarCascade("frontalface", stages=17)
#print(face_cascade)
n = 20 #设置每个人拍摄图片数量。
clock = time.clock()
while (n):
clock.tick()
img = sensor.snapshot()
pyb.LED(RED_LED_PIN).on()
sensor.skip_frames(time = 3000) # 等待3s,准备一下表情。
#红灯灭,蓝灯亮
pyb.LED(RED_LED_PIN).off()
pyb.LED(BLUE_LED_PIN).on()
#保存截取到的图片到SD卡
objects = img.find_features(face_cascade, threshold=0.85, scale=1.1)
for r in objects:
img = img.draw_rectangle(r)
d = ''.join(d)
print(d)
img.save("singtong/%s/%s.pgm" %(d,n))# ,roi = r)
n -= 1
#print(r)
pyb.LED(BLUE_LED_PIN).off()