Ejemplo n.º 1
0
def show_all_landmarks(img):
    W = 800
    result = dde.get("landmarks_ar")
    min = numpy.min(result)
    result -= min
    result *= 2
    mean_x, mean_y = result[::3].mean(), result[1::3].mean()
    print(mean_x, mean_y)

    zeros = numpy.zeros((W, W, 3), dtype=numpy.uint8)
    points = []
    for i in range(75):
        x = 800 - int(result[i * 3] - mean_x + 400)
        y = 800 - int(result[i * 3 + 1] - mean_y + 400)
        points.append((x, y))
        cv2.circle(zeros, (x, y), 1, (0, 255, 0), 2)
    draw_line(zeros, points)
    cv2.imshow("landmarks_ar", zeros)

    tmp = img
    result = dde.get("landmarks")
    points = []
    for i in range(75):
        points.append((result[i * 2], result[i * 2 + 1]))
        cv2.circle(tmp, (result[i * 2], result[i * 2 + 1]), 1, (0, 255, 0), 2)
    draw_line(tmp, points)
    cv2.imshow("landmarks", tmp)
    cv2.waitKey(30)
Ejemplo n.º 2
0
def get_anime_data_from_video(video_path, show, fbx, sil_frames):
    # dde.reset()
    noop_scan(video_path)
    console.log('log', 'Get anime data from video')
    cap = cv2.VideoCapture(video_path)
    anime_data = []
    frame_id = 0
    while True:
        ret, frame = cap.read()
        if not ret:
            break

        if frame_id in sil_frames:
            # print('sil')
            expr = numpy.zeros((46), dtype=numpy.float32)
            anime_data.append(numpy.zeros(
                (19),
                dtype=numpy.float32
            ))
        else:
            ret = False
            for _ in range(10):
                ret |= dde.run(frame)
                if ret:
                    break
            if not ret:
                console.log('error', 'Bad Frame', video_path + '\n')
                return None

            # print('speak')
            for _ in range(4):
                dde.run(frame)

            # push anime data
            expr = dde.get('expression_raw')
            anime_data.append(numpy.asarray(
                dde.expr_to_mouth(expr),
                dtype=numpy.float32))

        frame_id += 1

        if show:
            lm = dde.get('landmarks')
            for i in range(0, lm.shape[0], 2):
                x = lm[i]
                y = lm[i + 1]
                cv2.circle(frame, (x, y), 1, (0, 255, 0), -1)
                cv2.imshow('frame', frame)

        if fbx:
            mat = fbxanime.get_image(expr)
            cv2.imshow('fbx', mat)

        if show or fbx:
            cv2.waitKey(1)

    cap.release()
    return anime_data
Ejemplo n.º 3
0
def landmarks_ar():
    result = dde.get("landmarks_ar")
    min = numpy.min(result)
    result -= min
    result *= 2
    mean_x, mean_y = result[::3].mean(), result[1::3].mean()

    lm = []
    for i in range(75):
        lm.append((mean_x - result[i * 3], mean_y - result[i * 3 + 1]))
    return lm