"--tta",
                        help="whether testCode time augmentation",
                        action="store_true")
    parser.add_argument("-c",
                        "--score",
                        default=False,
                        help="whether show the confidence score",
                        action="store_true")
    args = parser.parse_args()

    conf = get_config(False)

    mtcnn = MTCNN()
    print('mtcnn loaded')

    learner = face_learner(conf, True)
    learner.threshold = args.threshold
    if conf.device.type == 'cpu':
        learner.load_state(conf, 'ir_se50.pth', True, True)
    else:
        learner.load_state(conf, 'ir_se50.pth', True, True)
    learner.model.eval()
    print('learner loaded')

    if args.update:
        targets, names = prepare_facebank(conf,
                                          learner.model,
                                          mtcnn,
                                          tta=args.tta)
        print('facebank updated')
    else:
def predict():
        # image = Image.open(img_path)
        # img=img_path#注意修改

        parser = argparse.ArgumentParser(description='for face verification')
        parser.add_argument("-s", "--save", help="whether save", action="store_true")
        parser.add_argument('-th', '--threshold', help='threshold to decide identical faces', default=1.54,
                            type=float)
        parser.add_argument("-u", "--update", default=True, help="whether perform update the facebank",
                            action="store_true")
        parser.add_argument("-tta", "--tta", default=False, help="whether testCode time augmentation",
                            action="store_true")
        parser.add_argument("-c", "--score", default=True, help="whether show the confidence score",
                            action="store_true")
        parser.add_argument('--img_path', '-p', default='1.jpg', type=str,
                            help='input the name of the recording person')
        args = parser.parse_args()
        mtcnn = MTCNN()
        conf = get_config(False)
        learner = face_learner(conf, True)
        learner.threshold = args.threshold
        # image = Image.open(args.img_path)

        if conf.device.type == 'cpu':
                learner.load_state(conf, 'ir_se50.pth', True, True)
        else:
                learner.load_state(conf, 'ir_se50.pth', True, True)
        learner.model.eval()
        print('learner loaded')

        if args.update:
                targets, names = prepare_facebank(conf, learner.model, mtcnn, tta=args.tta)
                print('facebank updated')
        else:
                targets, names = load_facebank(conf)
                print('facebank loaded')

        # inital camera
        cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
        cap.set(3, 1280)
        cap.set(4, 720)
        if args.save:
                video_writer = cv2.VideoWriter('D:/code/Python/InsightFace_Pytorch-masterxin/InsightFace_Pytorch-master'
                                               '/work_space/save/recording.avi', cv2.VideoWriter_fourcc(*'XVID'), 6,
                                               (1280,
                                                720))
                # frame rate 6 due to my laptop is quite slow...
        while cap.isOpened():
                # 获取一帧一帧的三维图像
                isSuccess, frame = cap.read()
                if isSuccess:
                        try:
                                image = Image.fromarray(frame)
                                # 利用mtcnn网络,对齐
                                bboxes, faces = mtcnn.align_multi(image, conf.face_limit, conf.min_face_size)
                                bboxes = bboxes[:, :-1]  # shape:[10,4],only keep 10 highest possibiity faces
                                bboxes = bboxes.astype(int)
                                bboxes = bboxes + [-1, -1, 1, 1]  # personal choice
                                results, score = learner.infer(conf, faces, targets, args.tta)
                                print(results, score)
                                for idx, bbox in enumerate(bboxes):
                                        if args.score:
                                                frame = draw_box_name(bbox, names[results[idx] + 1] + '_{:.2f}'.format(
                                                        score[idx]), frame)
                                                print(names[results[idx] + 1])
                                                res = names[results[idx] + 1]
                                        else:
                                                frame = draw_box_name(bbox, names[results[idx] + 1], frame)
                                                print(names[results[idx] + 1])
                                                res = names[results[idx] + 1]
                        except:
                                print('detect')
                                res = "unknow"

                        cv2.imshow('face Capture', frame)



                """打开数据库"""

                db = cx_Oracle.connect('fgos', 'bjrdfgos', '172.20.19.156:1521/fgosora')
                # 使用cursor()方法获取操作游标
                cursor = db.cursor()
                # sql = "SELECT * FROM names where name='%res'"
                # 使用execute方法执行SQL语句
                cursor.execute("SELECT * FROM v$TD_VIP_TEST where VIPU_VIP_NAME='%s'" % (res))

        # 使用 fetchone() 方法获取一条数据
        dat = cursor.fetchone()
        print(dat)
        # 关闭数据库连接
        db.close()
Ejemplo n.º 3
0
def predict(image):
    # image = Image.open(img_path)
    # img=img_path#注意修改

    parser = argparse.ArgumentParser(description='for face verification')
    parser.add_argument("-s",
                        "--save",
                        help="whether save",
                        action="store_true")
    parser.add_argument('-th',
                        '--threshold',
                        help='threshold to decide identical faces',
                        default=1.54,
                        type=float)
    parser.add_argument("-u",
                        "--update",
                        default=True,
                        help="whether perform update the facebank",
                        action="store_true")
    parser.add_argument("-tta",
                        "--tta",
                        default=False,
                        help="whether testCode time augmentation",
                        action="store_true")
    parser.add_argument("-c",
                        "--score",
                        default=True,
                        help="whether show the confidence score",
                        action="store_true")
    parser.add_argument('--img_path',
                        '-p',
                        default='1.jpg',
                        type=str,
                        help='input the name of the recording person')
    args = parser.parse_args()
    mtcnn = MTCNN()
    conf = get_config(False)
    learner = face_learner(conf, True)
    learner.threshold = args.threshold
    # image = Image.open(args.img_path)

    if conf.device.type == 'cpu':
        learner.load_state(conf, 'ir_se50.pth', True, True)
    else:
        learner.load_state(conf, 'ir_se50.pth', True, True)
    learner.model.eval()
    print('learner loaded')

    if args.update:
        targets, names = prepare_facebank(conf,
                                          learner.model,
                                          mtcnn,
                                          tta=args.tta)
        print('facebank updated')
    else:
        targets, names = load_facebank(conf)
        print('facebank loaded')

    try:
        # image = Image.fromarray(img)
        # 利用mtcnn网络,对齐
        bboxes, faces = mtcnn.align_multi(image, conf.face_limit,
                                          conf.min_face_size)
        bboxes = bboxes[:, :
                        -1]  # shape:[10,4],only keep 10 highest possibiity faces
        bboxes = bboxes.astype(int)
        bboxes = bboxes + [-1, -1, 1, 1]  # personal choice
        results, score = learner.infer(conf, faces, targets, args.tta)
        print(results, score)
        for idx, bbox in enumerate(bboxes):
            print(names[results[idx] + 1])
            res = names[results[idx] + 1]
    except:
        print('detect')
        res = "unknow"
    """打开数据库"""
    #                       主机         用户名     密码     建立的数据库     编码格式
    db = pymysql.connect(host='203.176.95.7',
                         port=3306,
                         user='******',
                         passwd='123123ms@',
                         database='FaceBank',
                         charset='utf8')
    # 使用cursor()方法获取操作游标
    cursor = db.cursor()
    # sql = "SELECT * FROM names where name='%res'"
    # 使用execute方法执行SQL语句
    cursor.execute("SELECT * FROM names where name='%s'" % (res))

    # 使用 fetchone() 方法获取一条数据
    dat = cursor.fetchone()
    print(dat)
    # 关闭数据库连接
    db.close()

    return dat
def predict(image):
    # image = Image.open(img_path)
    # img=img_path#注意修改

    parser = argparse.ArgumentParser(description='for face verification')
    parser.add_argument("-s",
                        "--save",
                        help="whether save",
                        action="store_true")
    parser.add_argument('-th',
                        '--threshold',
                        help='threshold to decide identical faces',
                        default=1.54,
                        type=float)
    parser.add_argument("-u",
                        "--update",
                        default=True,
                        help="whether perform update the facebank",
                        action="store_true")
    parser.add_argument("-tta",
                        "--tta",
                        default=False,
                        help="whether testCode time augmentation",
                        action="store_true")
    parser.add_argument("-c",
                        "--score",
                        default=True,
                        help="whether show the confidence score",
                        action="store_true")
    parser.add_argument('--img_path',
                        '-p',
                        default='1.jpg',
                        type=str,
                        help='input the name of the recording person')
    args = parser.parse_args()
    mtcnn = MTCNN()
    conf = get_config(False)
    learner = face_learner(conf, True)
    learner.threshold = args.threshold
    # image = Image.open(args.img_path)

    if conf.device.type == 'cpu':
        learner.load_state(conf, 'ir_se50.pth', True, True)
    else:
        learner.load_state(conf, 'ir_se50.pth', True, True)
    learner.model.eval()
    print('learner loaded')

    if args.update:
        targets, names = prepare_facebank(conf,
                                          learner.model,
                                          mtcnn,
                                          tta=args.tta)
        print('facebank updated')
    else:
        targets, names = load_facebank(conf)
        print('facebank loaded')

    try:
        # image = Image.fromarray(img)
        # 利用mtcnn网络,对齐
        bboxes, faces = mtcnn.align_multi(image, conf.face_limit,
                                          conf.min_face_size)
        bboxes = bboxes[:, :
                        -1]  # shape:[10,4],only keep 10 highest possibiity faces
        bboxes = bboxes.astype(int)
        bboxes = bboxes + [-1, -1, 1, 1]  # personal choice
        results, score = learner.infer(conf, faces, targets, args.tta)
        print(results, score)
        for idx, bbox in enumerate(bboxes):
            print(names[results[idx] + 1])
            res = "name:" + names[results[idx] + 1]
    except:
        print('detect')
        res = "unknow"

    return res