@kidswong999 谢谢哥,问题解决啦。不过你说我买个好点的摄像头应该提高人脸识别精度吧???
N
natp
@natp
0
声望
4
楼层
241
资料浏览
0
粉丝
0
关注
natp 发布的帖子
-
RE: 像我这个问题咋解决呀?不知道修改哪里?
@kidswong999 不过为啥我用if语句的时候就没报错呢?我还运行出来了。虽然识别过程有点艰难。
if x==2: #如果画面中出现两个人 z1=objects[0] #print(z) d0 = img.find_lbp(z1) #print(d0) img = None pmin = 999999 num=0 def min(pmin, a, s): global num if a<pmin: pmin=a num=s return pmin for s in range(1, NUM_SUBJECTS+1): dist = 0 for i in range(2, NUM_SUBJECTS_IMGS+1): img = image.Image("a123/s%d/%d.pgm"%(s, i)) d1 = img.find_lbp((0, 0, img.width(), img.height())) dist += image.match_descriptor(d0, d1) #print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS)) pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)#特征差异度越小,被检测人脸与此样本更相似更匹配。 #print(pmin) z2=objects[1] #print(z2) d2 = img.find_lbp(z2) #print(d2) img = None pmin = 999999 num=0 def min(pmin, a, s): global num if a<pmin: pmin=a num=s return pmin for s in range(1, NUM_SUBJECTS+1): dist = 0 for i in range(2, NUM_SUBJECTS_IMGS+1): img = image.Image("a123/s%d/%d.pgm"%(s, i)) d1 = img.find_lbp((0, 0, img.width(), img.height())) dist += image.match_descriptor(d2, d1) #print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS)) pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)#特征差异度越小,被检测人脸与此样本更相似更匹配。 #print(pmin)
-
像我这个问题咋解决呀?不知道修改哪里?
import sensor, time, image, pyb sensor.reset() sensor.set_contrast(3) sensor.set_gainceiling(16) sensor.set_framesize(sensor.HQVGA) sensor.set_pixformat(sensor.GRAYSCALE) rtc = pyb.RTC() rtc.datetime((2022, 3, 29, 7, 7, 40, 0, 0)) NUM_SUBJECTS = 6 #图像库中不同人数,一共6人 NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片 # 加载Haar算子 # 默认情况下,这将使用所有阶段,更低的satges更快,但不太准确。 face_cascade = image.HaarCascade("frontalface", stages=25) while (True): img = sensor.snapshot()# 拍摄一张照片 objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #print(objects) for r in objects: #识别人脸画矩形框 img.draw_rectangle(r) x=len(objects) if x>=1: print(x) c=0 while c<x: z=objects[c] print(c) d0 = img.find_lbp(z) print(z) c=c+1 img = None pmin = 999999 num=0 def min(pmin, a, s): global num if a<pmin: pmin=a num=s return pmin for s in range(1, NUM_SUBJECTS+1): dist = 0 for i in range(2, NUM_SUBJECTS_IMGS+1): img = image.Image("a123/s%d/%d.pgm"%(s, i)) d1 = img.find_lbp((0, 0, img.width(), img.height())) dist += image.match_descriptor(d0, d1) print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS)) pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)#特征差异度越小,被检测人脸与此样本更相似更匹配。 print(pmin)