Esempio n. 1
0
    result_path = Path(args.result_path).expanduser().resolve()
    if not result_path.exists():
        result_path.mkdir(parents=True)

    path_to_save = Path(result_path, video_path.name).as_posix()

    cap = cv2.VideoCapture(video_path.as_posix())

    width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

    fourcc = cv2.VideoWriter_fourcc(*"mp4v")
    video_writer = cv2.VideoWriter(path_to_save, fourcc, 24.0, (width, height))

    video_len = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    for _ in tqdm(range(video_len)):
        ret, frame = cap.read()
        img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

        bboxes, landmarks, user_ids, similarities = system.sdk.recognize_faces(img)
        names = [system.get_user_name(uid) for uid in user_ids]

        draw_boxes(img, bboxes, name_tags=names, similarities=similarities)
        draw_landmarks(img, landmarks)

        img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
        video_writer.write(img)

    cap.release()
    video_writer.release()
Esempio n. 2
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--path", "-p", help="path to image", type=str)
    parser.add_argument(
        "--config", help="path to sdk config", type=str, default="face_recognition_sdk/config/config.yaml"
    )
    parser.add_argument("--result_path", "-r", help="path to save processed image", default="demo/results")
    args = parser.parse_args()

    config = read_yaml(args.config)

    sdk = FaceRecognitionSDK(config=config)

    img_path = Path(args.path).expanduser().resolve()
    img = cv2.imread(img_path.as_posix())
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

    boxes, landms = sdk.detect_faces(img)

    draw_boxes(img, boxes)
    draw_landmarks(img, landms)

    result_path = Path(args.result_path).expanduser().resolve()
    if not result_path.exists():
        result_path.mkdir(parents=True)

    img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)

    path_to_save = Path(result_path, img_path.name)
    cv2.imwrite(path_to_save.as_posix(), img)