Ejemplo n.º 1
0
    detector = RetinaFace(0)
    cap = cv2.VideoCapture(0)
    faces = None
    results = None
    while True:
        start = time.time()
        ret, img = cap.read()
        if not ret:
            break
        if faces is None:  # 只在第一帧检测
            faces = detector(img, cv=True, threshold=0.5)
        else:
            ldm_new = results[0]
            (x1, y1), (x2, y2) = ldm_new.min(0), ldm_new.max(0)
            box_new = np.array([x1, y1, x2, y2])
            box_new[:2] -= 10
            box_new[2:] += 10
            faces = [[box_new, None, None]]

        if len(faces) == 0:
            print("NO face is detected!")
            continue
        else:
            results = predictor(faces, img, from_fd=True)
            for face, landmarks in zip(faces, results):
                img = drawLandmark_multiple(img, face[0], landmarks)

        cv2.imshow("", img)
        cv2.waitKey(1)
        print("FPS=", 1 / (time.time() - start))
Ejemplo n.º 2
0
    faces = None
    results = None
    recon_landmarks = []
    while True:
        ret, img = cap.read()
        start = time.time()
        if not ret:
            break
        if faces is None:
            faces = detector(img, cv=True, threshold=0.5)

        img_for_show = img.copy()
        if len(faces) == 0:
            print("NO face is detected!")
            continue
        else:
            if results is None:
                results = predictor(faces, img, from_fd=True)
            faces = faces_from_results(results)
            boxes = [face[0] for face in faces]
            recon_results = regressor(boxes, img)
            results = []
            for recon_res, box in zip(recon_results, boxes):
                pts = recon_res["pts68"]
                results.append(pts)
                img_for_show = drawLandmark_multiple(img_for_show, box, pts)

        cv2.imshow("", img_for_show)
        print("FPS=", 1 / (time.time() - start))
        cv2.waitKey(1)