代码就是检测到有人,就把视线内的所有人脸与SD卡里的人脸对比,SD卡里图片是用openmv的VGA像素拍摄的,有90多KB。一读取就内存报错MemoryError: Out of normal MicroPython Heap Memory!。代码和要比对的图片如下:
# Face recognition with LBP descriptors.
# See Timo Ahonen's "Face Recognition with Local Binary Patterns".
#
# Before running the example:
# 1) Download the AT&T faces database http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip
# 2) Exract and copy the orl_faces directory to the SD card root.
import sensor, time, image, pyb
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.VGA) # or sensor.QQVGA (or others)
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
i = 1
# 拍摄当前人脸。
face_cascade = image.HaarCascade("frontalface", stages=25)
while(True):
img = sensor.snapshot()
#img = image.Image("singtown/%s/1.pgm"%(SUB))
objects = img.find_features(face_cascade, threshold=0.75, scale=1.35)
if not objects :
print("no people")
continue
for face in objects:
d0 = img.find_lbp(face)
img = image.Image("%d.pgm"%i)
d1 = img.find_lbp((0, 0, img.width(), img.height()))
dist = image.match_descriptor(d0, d1)#计算d0 d1即样本图像与被检测人脸的特征差异度。
if dist >28000:
print("people is not match")
else:
print("There's a match here ")
由于不能上传pgm格式图片,我把拓展名改成了jpg格式,麻烦一下您下载后把拓展名改回pgm格式,然后试一下。谢谢!
我测试没问题,固件3.6.4
face.pgm就是你上传的图片。
