Esempio n. 1
0
def Feature_extract_batch(fun, files_list, names_list):
    asf_embeddings = []    # 特征
    asf_label_list = []    # 标签
    for img_path, name in zip(files_list, names_list):
        print("processing image: {}".format(img_path))

        im = face_class.IM()
        im.filepath = img_path
        im = fun.LoadImg(im)    # 加载图片

        ret = fun.face_detect(im)    # 人脸检测
        if ret == -1:
            print('人脸检测失败:', ret)
            continue
        faces = ret
        if faces.faceNum != 1:
            print("-----image total {} faces, continue...".format(faces.faceNum))
            continue

        ft = fun.getSingleFace(faces, 0)  # 从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
        # asf_embeddings_size.append(fea.featureSize)    # 特征的大小,feature.featureSize
        asf_embeddings.append(fea)    # feature,ASF_FaceFeature类型,包括:feature.featureSize, feature.feature
        asf_label_list.append(name)           # 标签
    return asf_embeddings, asf_label_list
Esempio n. 2
0
        print('初始化失败:', ret)

    # 3.加载库中图片特征及标签
    asf_dataset_emb, asf_name_list = fun.loadFeatureFromDB()

    print("asf_dataset_emb:", asf_dataset_emb)
    print("asf_name_list:", asf_name_list)

    cap = cv2.VideoCapture(0)
    while True:
        ret, frame = cap.read()    # frame.shape:(480, 640, 3),(高,宽,通道)
        if frame is None:
            break

        frame = cv2.resize(frame, (frame.shape[1] // 4 * 4, frame.shape[0] // 4 * 4))  # 宽高要reshape成4的倍数,否则会报错:90127
        im = face_class.IM()
        im.data = frame
        im.width = frame.shape[1]
        im.height = frame.shape[0]

        ret = fun.face_detect(im)    # 人脸检测
        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个人的特征