调试人脸识别代码时同一条语句不定时出现不同错误。还有其他奇奇怪怪的bug也都不定时出现。运气好时可以连续运行一个小时。运气不好时一打开就崩溃。而且有时不报错直接崩




# 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.B128X128) # or sensor.QQVGA (or others)
sensor.set_windowing([0,0,127,127])#((92,112))
sensor.skip_frames(10) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s
sensor.set_contrast(1)
sensor.set_gainceiling(16)
face_cascade = image.HaarCascade("frontalface", stages=25)
#SUB = "s1"
NUM_SUBJECTS = 6 #图像库中不同人数,一共6人
NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片
# 拍摄当前人脸。
#img = sensor.snapshot()
##img = image.Image("singtown/%s/1.pgm"%(SUB))
#d0 = img.find_lbp((0, 0, img.width(), img.height()))
#d0为当前人脸的lbp特征
img = None
pmin = 999999
num=0
def min(pmin, a, s):
global num
if a<pmin:
pmin=a
num=s
return pmin
def max_face(objects):
face2=0
for face1 in objects:
face2=face1;
#if i==0:
#face2=objects[0]
#i=1;
#elif face1.w<objects[i].w:
#face2=objects[i]
return face2;
face=[0,0,127,127]
dist = 0
while(True):
img = sensor.snapshot()
objects = img.find_features(face_cascade, threshold=1.3, scale=1.5)
#face=max_face(objects);
if len(objects)==1:
for face in objects:
print(objects)
img.draw_rectangle(face);
if face[3]<50:
continue;
elif face[2]>55:
continue;
sensor.set_windowing(face)
d0 = img.find_lbp(face) #((0, 0, img.width(), img.height()))
pmin=9999999;
for s in range(1, NUM_SUBJECTS+1):
dist = 0
for i in range(2, NUM_SUBJECTS_IMGS+1):
img = image.Image("singtown/s%d/%d.pgm"%(s, i)) #pgm
d1 = img.find_lbp((0, 0, img.width(), img.height()))
#d1为第s文件夹中的第i张图片的lbp特征
dist += image.match_descriptor(d0, d1)#计算d0 d1即样本图像与被检测人脸的特征差异度。
print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS))
pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)#特征差异度越小,被检测人脸与此样本更相似更匹配。
print(pmin)
print(num) # num为当前最匹配的人的编号。
sensor.set_windowing([0,0,127,127])#((92,112))
sensor.skip_frames(time = 200)你用的是什么硬件,什么版本固件?
H7的 固件是3.6.8
刚刚又爆了个错误 但是忘截图了

@kidswong999 我刚刚又换了个F7试了下 依然存在若干bug随机出现的问题 再比如还有这个:

@kidswong999 实在不会了。救救孩子吧:crying_face: