if ret == -1: print('人脸检测失败:', ret) pass # 5.显示检测结果,这时face_detect()返回的是faces faces = ret for i in range(0, faces.faceNum): ra = faces.faceRect[i] ft = fun.getSingleFace(faces, i) # 从faces集中,提取第0个人的特征 # print("ft:", ft.faceRect.left1, ft.faceRect.top1, ft.faceRect.right1, ft.faceRect.bottom1, ft.faceOrient) ret, fea = fun.Feature_extract(im, ft) # 返回tuple,(标识, 特征) if ret != 0: print("特征提取失败!") continue pred_name, pred_score = fun.asf_compare_embadding(fea, asf_dataset_emb, asf_name_list) # 识别标签,分数 # print("pred_name===pred_score", pred_name, pred_score) # 这里在图上画框标记 if pred_name is not None: # 标签不为空,说明识别到了 cv2.rectangle(im.data, (ra.left1, ra.top1), (ra.right1, ra.bottom1), (255, 0, 0), 2) showInfo = pred_name + ": " + str(pred_score)[:5] # 分数只保留小数点后3位置 zh_cn_nums = general_util.get_zhcn_number(showInfo) # 中文的字数(一个中文字20个像素宽,一个英文字10个像素宽) t_size = (20 * zh_cn_nums + 10 * (len(showInfo) - zh_cn_nums), 22) c2 = ra.left1 + t_size[0], ra.top1 - t_size[1] - 3 # 纵坐标,多减3目的是字上方稍留空 cv2.rectangle(im.data, (ra.left1, ra.top1), c2, (0, 0, 255), -1) # filled # print("t_size:", t_size, " c1:", c1, " c2:", c2) # Draw a label with a name below the face # cv2.rectangle(im0, c1, c2, (0, 0, 255), cv2.FILLED) font = cv2.FONT_HERSHEY_DUPLEX
box = bboxes[i] # ft = fun.getSingleFace(faces, i) # 从faces集中,提取第0个人的特征 # print("ft:", ft.faceRect.left1, ft.faceRect.top1, ft.faceRect.right1, ft.faceRect.bottom1, ft.faceOrient) ft = face_class.ASF_SingleFaceInfo() # 单个人的信息 ft.faceRect.left1 = c_int32(box[0]) ft.faceRect.top1 = c_int32(box[1]) ft.faceRect.right1 = c_int32(box[2]) ft.faceRect.bottom1 = c_int32(box[3]) ft.faceOrient = c_int32(1) # 方向随便写个 ret, fea = fun.Feature_extract(im, ft) # 返回tuple,(标识, 特征) if ret == 0: # 特征提取成功 pred_name, pred_score = fun.asf_compare_embadding( fea, ASF_FaceFeature_List, ASF_Name_List, threshold=0.8) # 识别标签,分数 # print(pred_name, pred_score) if pred_name == name: # 如果识别姓名和标记姓名相同,则认为识别正确 correct_nums += 1 reco_result.append((file, name, pred_name, pred_score, box)) # 文件名,标注名,识别名,置信度,人脸框 else: # 同一帧图片有多个人脸的情况,“特征提取失败”会打印多次 # 这时报错81925,表示人脸特征检测结果置信度低,说明mtcnn认为是人脸,而asf不认为这是人脸,提取特征的置信度低 log.logger.warn("特征提取失败:%s,%s,人脸个数:%d,失败点:%s" % (ret, file, len(bboxes), box)) feature_failed_result.append((file, name, box)) # 8.测评完成 log.logger.info("EVAL finished! Accuracy: %.3f %%" %