@kidswong999看过写字例程还是不会加啊 不知道该怎么加,加在哪里,帮忙看看吧
P
pbyz
@pbyz
0
声望
16
楼层
598
资料浏览
0
粉丝
0
关注
pbyz 发布的帖子
-
RE: 做人脸识别和分辨不同人脸例程时,识别成功后在人脸框上显示对应人员编号要怎么加代码,加在哪里?
-
做人脸识别和分辨不同人脸例程时,识别成功后在人脸框上显示对应人员编号要怎么加代码,加在哪里?
import sensor, time, image, pyb import lcd RED_LED_PIN = 1 GREEN_LED_PIN = 2 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((92,112)) lcd.init() # Initialize the lcd screen. #lcd初始化 face_cascade = image.HaarCascade("frontalface", stages=25) #SUB = "s1" NUM_SUBJECTS = 1 #图像库中不同人数,一共2人 NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片 # 拍摄当前人脸。 while (True): lcd.display(sensor.snapshot().histeq()) # Take a picture and display the image. #将图像显示在lcd中 img = sensor.snapshot().histeq() img.median(0, percentile=0.5) objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #img = image.Image("face/%s/1.pgm"%(SUB)) if not objects: pyb.LED(GREEN_LED_PIN).off() pyb.LED(RED_LED_PIN).on() print("没有检测到人脸") for r in objects: img.draw_rectangle(r) img = sensor.snapshot().histeq() img.median(0, percentile=0.5) 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 for s in range(1, NUM_SUBJECTS+1): dist = 0 for i in range(2, NUM_SUBJECTS_IMGS+1): img = image.Image("face/s%d/%d.pgm"%(s, i)) 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) for r in objects: if pmin < 7000: pyb.LED(GREEN_LED_PIN).on() print(num) else: pyb.LED(GREEN_LED_PIN).off() pyb.LED(RED_LED_PIN).on() print("识别失败")
-
RE: 怎样将人脸识别和分辨不同人脸结合起来,就是先识别到有人脸存在,再进行LBP特征计算
上面是我现在的代码,是人脸检测和人脸分辨同时进行,要怎样改成先检测有无人脸存在,有人脸则计算LBP特征值,无人脸则直接输出无人脸?
-
怎样将人脸识别和分辨不同人脸结合起来,就是先识别到有人脸存在,再进行LBP特征计算
import sensor, time, image, pyb import lcd RED_LED_PIN = 1 GREEN_LED_PIN = 2 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((92,112)) lcd.init() # Initialize the lcd screen. #lcd初始化 face_cascade = image.HaarCascade("frontalface", stages=25) #SUB = "s1" NUM_SUBJECTS = 3 #图像库中不同人数,一共3人 NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片 # 拍摄当前人脸。 while (True): img = sensor.snapshot() objects = img.find_features(face_cascade, threshold=0.75, scale=1.35) #img = image.Image("face/%s/1.pgm"%(SUB)) for r in objects: img.draw_rectangle(r) img = sensor.snapshot() 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 for s in range(1, NUM_SUBJECTS+1): dist = 0 for i in range(2, NUM_SUBJECTS_IMGS+1): img = image.Image("face/s%d/%d.pgm"%(s, i)) 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) if pmin < 6000: pyb.LED(GREEN_LED_PIN).on() print(num) else: pyb.LED(GREEN_LED_PIN).off() pyb.LED(RED_LED_PIN).on() print(0) lcd.display(sensor.snapshot()) # Take a picture and display the image. #将图像显示在lcd中