Esempio n. 1
0
def main(args, color=(224, 255, 255)):
    fd = service.UltraLightFaceDetecion("weights/RFB-320.tflite",
                                        conf_threshold=0.95)

    if args.mode in ["sparse", "pose"]:
        fa = service.DepthFacialLandmarks("weights/sparse_face.tflite")
    else:
        fa = service.DenseFaceReconstruction("weights/dense_face.tflite")
        if args.mode == "mesh":
            color = service.TrianglesMeshRender("asset/render.so",
                                                "asset/triangles.npy")

    handler = getattr(service, args.mode)
    cap = cv2.VideoCapture(args.filepath)

    while True:
        ret, frame = cap.read()

        if not ret:
            break

        # face detection
        boxes, scores = fd.inference(frame)

        # raw copy for reconstruction
        feed = frame.copy()

        for results in fa.get_landmarks(feed, boxes):
            handler(frame, results, color)

        # cv2.imwrite(f'draft/gif/trans/img{counter:0>4}.jpg', frame)

        cv2.imshow("demo", frame)
        if cv2.waitKey(1) == ord("q"):
            break
def main(args, color=(224, 255, 255)):
    fd = service.UltraLightFaceDetecion("weights/RFB-320.tflite",
                                        conf_threshold=0.92)

    if args.mode in ["sparse", "pose"]:
        fa = service.DepthFacialLandmarks("weights/sparse_face.tflite")
    else:
        fa = service.DenseFaceReconstruction("weights/dense_face.tflite")
        if args.mode == "mesh":
            mr = service.TrianglesMeshRender("asset/render.so",
                                             "asset/triangles.npy")

    cap = cv2.VideoCapture(args.filepath)

    while True:
        ret, frame = cap.read()

        if not ret:
            break

        # face detection
        boxes, scores = fd.inference(frame)

        # raw copy for reconstruction
        feed = frame.copy()

        for landmarks, pose in fa.get_landmarks(feed, boxes):

            if args.mode == "sparse":
                landmarks = np.round(landmarks).astype(np.int)
                for p in landmarks:
                    cv2.circle(frame, tuple(p), 2, color, 0, cv2.LINE_AA)
                draw_poly(frame, landmarks, color=color)

            elif args.mode == "dense":
                landmarks = np.round(landmarks).astype(np.int)
                landmarks = landmarks[:2].T
                for p in landmarks[::6]:
                    cv2.circle(frame, tuple(p), 1, color, 0, cv2.LINE_AA)

            elif args.mode == "mesh":
                landmarks = landmarks.astype(np.float32)
                mr.render(landmarks.T.copy(), frame)

        cv2.imshow("result", frame)
        if cv2.waitKey(1) == ord('q'):
            break
Esempio n. 3
0
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy as np
import sys
import cv2
import service
import time

fd = service.UltraLightFaceDetecion("weights/RFB-320.tflite",
                                    conf_threshold=0.92)
fa = service.DenseFaceReconstruction("weights/dense_face.tflite")
mr = service.TrianglesMeshRender("asset/render.so", "asset/triangles.npy")

cap = cv2.VideoCapture(sys.argv[1])
counter, rate = 0, cap.get(5)

while True:
    ret, frame = cap.read()

    if not ret:
        break

    # face detection
    start_time = time.perf_counter()
    boxes, scores = fd.inference(frame)
    detect_cost = time.perf_counter() - start_time

    # raw copy for reconstruction
    feed = frame.copy()