コード例 #1
0
def app(image_path):
    image = cv.imread(image_path)
    assert image is not None

    face_detector = FaceDetector()
    face_landmarker = FaceLandmarker()

    scores, bboxes = face_detector.getFaces(image, def_score=0.5)
    landmarks = []
    for i, bbox in enumerate(bboxes):
        x1, y1, x2, y2 = bbox
        face_img = image[y1:y2, x1:x2]
        landmark = face_landmarker.getLandmark(face_img)
        landmark[:, :] += np.array([x1, y1])
        landmarks.append(landmark)

    for i, landmark in enumerate(landmarks):
        aligned_img = align(image, bboxes[i], landmark)
        cv.imshow(str(i), aligned_img)

    if len(bboxes):
        for i, landmark in enumerate(landmarks):
            for j, point in enumerate(landmark):
                cv.circle(image, tuple(point), 3, (0, 255, 0), -1)

        image = vis.plotBBoxes(image, bboxes)
        image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

    cv.imshow(image_path, image)
    cv.waitKey(0)
コード例 #2
0
def app(video_link, video_name, show, flip_hor, flip_ver):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    # initialize Video Capturer
    cap = cv.VideoCapture(video_link)
    (W, H), FPS = imgproc.cameraCalibrate(cap, size=720, by_height=True)
    LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))

    while cap.isOpened():
        _, frm = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        if flip_ver: frm = cv.flip(frm, 0)
        if flip_hor: frm = cv.flip(frm, 1)

        frm = imgproc.resizeByHeight(frm, 720)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(frm, def_score=0.5)

        landmarks = []
        for i, bbox in enumerate(bboxes):
            x1, y1, x2, y2 = bbox
            face_img = frm[y1:y2, x1:x2]
            landmark = face_landmarker.getLandmark(face_img)
            landmark[:, :] += np.array([x1, y1])
            landmarks.append(landmark)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            for i, landmark in enumerate(landmarks):
                for j, point in enumerate(landmark):
                    cv.circle(frm, tuple(point), 3, (0, 255, 0), -1)

            frm = vis.plotBBoxes(frm, bboxes, len(bboxes) * ['face'], scores)

        frm = vis.plotInfo(frm,
                           'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        frm = cv.cvtColor(np.asarray(frm), cv.COLOR_BGR2RGB)

        if show:
            cv.imshow(video_name, frm)
            key = cv.waitKey(1)
            if key in [27, ord('q')]:
                LOG.info('Interrupted by Users')
                break

    cap.release()
    cv.destroyAllWindows()
コード例 #3
0
def app(image1_path, image2_path):
    # initialize Face detector net
    detector = FaceDetector()

    # initialize Face Landmarker net
    landmarker = FaceLandmarker()

    # initialize Face Aligner
    aligner = FaceAligner()

    # intializa Face Embedder
    embedder = FaceEmbedder()
    # ================================================================

    image1 = cv.imread(image1_path)
    image2 = cv.imread(image2_path)
    assert image1 is not None and image2 is not None
    # ================================================================

    _, faces_1 = detector.getFaces(image1)
    _, faces_2 = detector.getFaces(image2)
    assert len(faces_1) and len(faces_2)
    # ================================================================

    x1, y1, x2, y2 = faces_1[0]
    face_image1 = image1[y1:y2, x1:x2]
    lm1 = landmarker.getLandmark(face_image1)
    aligned_face1 = aligner.align(face_image1, lm1)

    x1, y1, x2, y2 = faces_2[0]
    face_image2 = image2[y1:y2, x1:x2]
    lm2 = landmarker.getLandmark(face_image2)
    aligned_face2 = aligner.align(face_image2, lm2)
    # ================================================================

    emb1 = embedder.getEmb(face_image1)
    LOG.info('emb1 shape: {}'.format(emb1.shape))

    emb2 = embedder.getEmb(face_image2)
    LOG.info('emb2 shape: {}'.format(emb2.shape))

    dist = getDistance(emb1, emb2)
    LOG.info('distance: {:.4}'.format(dist))
コード例 #4
0
def app(image_path):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    cap = cv.VideoCapture(0)
    while cap.isOpened():
        _, image = cap.read()
        if not _:
            LOG.info('Reached the end of Video source')
            break

        image = imgproc.resizeByHeight(image, 720)

        _start_t = time.time()
        scores, bboxes = face_detector.getFaces(image, def_score=0.5)

        landmarks = []
        for i, bbox in enumerate(bboxes):
            x1, y1, x2, y2 = bbox
            face_img = image[y1:y2, x1:x2]
            landmark = face_landmarker.getLandmark(face_img)

            aligned_img = alignFace(face_img, landmark)
            cv.imshow('aligned-faces' + str(i), aligned_img)

            landmark[:, :] += np.array([x1, y1])
            landmarks.append(landmark)
        _prx_t = time.time() - _start_t

        if len(bboxes):
            for i, landmark in enumerate(landmarks):
                for j, point in enumerate(landmark):
                    cv.circle(image, tuple(point), 3, (0, 255, 0), -1)

            image = vis.plotBBoxes(image, bboxes,
                                   len(bboxes) * ['face'], scores)

        image = vis.plotInfo(image,
                             'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
        image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

        cv.imshow(image_path, image)
        key = cv.waitKey(1)
        if key in [27, ord('q')]:
            LOG.info('Interrupted by Users')
            break

    cap.release()
    cv.destroyAllWindows()
コード例 #5
0
def app(image_path):
    # initialize Face Detection net
    face_detector = FaceDetector()
    LOG.info('Face Detector initialization done')

    # initialize Face Landmark net
    face_landmarker = FaceLandmarker()
    LOG.info('Face Landmarker initialization done')

    # initialize Face Alignment class
    face_aligner = FaceAligner()
    LOG.info('Face Aligner initialization done')

    # initialize Video Capturer
    image = cv.imread(image_path)
    assert image is not None

    image = imgproc.resizeByHeight(image, 720)

    _start_t = time.time()
    scores, bboxes = face_detector.getFaces(image, def_score=0.5)

    landmarks = []
    for i, bbox in enumerate(bboxes):
        x1, y1, x2, y2 = bbox
        face_img = image[y1:y2, x1:x2]
        landmark = face_landmarker.getLandmark(face_img)

        aligned_img = face_aligner.align(face_img, landmark)
        cv.imshow('aligned-faces' + str(i), aligned_img)

        landmark[:, :] += np.array([x1, y1])
        landmarks.append(landmark)
    _prx_t = time.time() - _start_t

    if len(bboxes):
        for i, landmark in enumerate(landmarks):
            for j, point in enumerate(landmark):
                cv.circle(image, tuple(point), 3, (0, 255, 0), -1)

        image = vis.plotBBoxes(image, bboxes, len(bboxes) * ['face'], scores)

    image = vis.plotInfo(image,
                         'Raspberry Pi - FPS: {:.3f}'.format(1 / _prx_t))
    image = cv.cvtColor(np.asarray(image), cv.COLOR_BGR2RGB)

    cv.imshow(image_path, image)
    key = cv.waitKey(0)

    cv.destroyAllWindows()