示例#1
0
        self.input_size = (128, 128)
    def get_feature(self, img):
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        img = cv2.resize(img, self.input_size, interpolation=cv2.INTER_AREA)
        blob = cv2.dnn.blobFromImage(img, scalefactor=1 / 127.5, mean=127.5)
        self.model.setInput(blob)
        output = self.model.forward(['output'])
        return output

if __name__ == '__main__':
    from yoloface_detect_align_module import yoloface    ###你还可以选择其他的人脸检测器

    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    # face_embdnet = arcface(device=device)
    face_embdnet = arcface_dnn()   ###已调试通过,与pytorch版本的输出结果吻合
    detect_face = yoloface(device=device)

    out_emb_path = 'yoloface_detect_arcface_feature.pkl'
    imgroot = '你的文件夹绝对路径'
    dirlist = os.listdir(imgroot)    ### imgroot里有多个文件夹,每个文件夹存放着一个人物的多个肖像照,文件夹名称是人名
    feature_list, name_list = [], []
    for i,name in enumerate(dirlist):
        sys.stdout.write("\rRun person{0}, name:{1}".format(i, name))
        sys.stdout.flush()

        imgdir = os.path.join(imgroot, name)
        imglist = os.listdir(imgdir)
        for imgname in imglist:
            srcimg = cv2.imread(os.path.join(imgdir, imgname))
            _, face_img = detect_face.detect(srcimg)  ###肖像照,图片中有且仅有有一个人脸
            if len(face_img)!=1:
        var_name for var_name, var_val in callers_local_vars if var_val is var
    ]


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Object Detection using YOLO in OPENCV')
    parser.add_argument('--imgpath',
                        type=str,
                        default='s_l.jpg',
                        help='Path to image file.')
    args = parser.parse_args()
    device = 'cuda' if torch.cuda.is_available() else 'cpu'
    align = False

    yoloface_detect = yoloface(device=device, align=align)
    ultraface_detect = ultraface()
    ssdface_detect = ssdface()
    retinaface_detect = retinaface(device=device, align=align)
    retinaface_dnn_detect = retinaface_dnn(align=align)
    mtcnn_detect = mtcnnface(device=device, align=align)
    facebox_detect = facebox(device=device)
    facebox_dnn_detect = facebox_dnn()
    dbface_detect = dbface(device=device, align=align)
    centerface_detect = centerface(align=align)
    lffdface_detect = lffdface(version=1)
    libface_detect = libfacedet(align=align)

    srcimg = cv2.imread(args.imgpath)

    a = time.time()