예제 #1
0
def is_new_frame_better(source, driving, precitor):
    global avatar_kp
    global display_string

    if avatar_kp is None:
        display_string = "No face detected in avatar."
        return False

    if predictor.get_start_frame() is None:
        display_string = "No frame to compare to."
        return True

    driving_smaller = resize(driving, (128, 128))[..., :3]
    new_kp = predictor.get_frame_kp(driving)

    if new_kp is not None:
        new_norm = (np.abs(avatar_kp - new_kp)**2).sum()
        old_norm = (np.abs(avatar_kp -
                           predictor.get_start_frame_kp())**2).sum()

        out_string = "{0} : {1}".format(int(new_norm * 100),
                                        int(old_norm * 100))
        display_string = out_string
        log(out_string)

        return new_norm < old_norm
    else:
        display_string = "No face found!"
        return False
예제 #2
0
파일: cam_fomm.py 프로젝트: MBtea/test
def load_images(IMG_SIZE=256):
    avatars = []
    images_list = sorted(glob.glob(f'{opt.avatars}/*'))
    for i, f in enumerate(images_list):
        if f.endswith('.jpg') or f.endswith('.jpeg') or f.endswith('.png'):
            key = len(avatars) + 1
            log(f'Key {key}: {f}')
            img = cv2.imread(f)
            if img.ndim == 2:
                img = np.tile(img[..., None], [1, 1, 3])
            img = img[..., :3][..., ::-1]
            img = resize(img, (IMG_SIZE, IMG_SIZE))
            avatars.append(img)
    return avatars
예제 #3
0
def check_connection(socket, timeout=1000):
    old_rcvtimeo = socket.RCVTIMEO
    socket.RCVTIMEO = timeout

    try:
        data = msgpack.packb(([], {}))
        socket.send_data('hello', data)
        attr_recv, data_recv = socket.recv_data()
        response = msgpack.unpackb(data_recv)
    except zmq.error.Again:
        return False
    finally:
        socket.RCVTIMEO = old_rcvtimeo

    log(f"Response to hello is {response}")

    return response == 'OK'
예제 #4
0
def query_cameras(n_cams):
    cam_frames = {}
    cap = None
    for camid in range(n_cams):
        log(f"Trying camera with id {camid}")
        cap = cv2.VideoCapture(camid)

        if not cap.isOpened():
            log(f"Camera with id {camid} is not available")
            continue

        ret, frame = cap.read()

        if not ret or frame is None:
            log(f"Could not read from camera with id {camid}")
            cap.release()
            continue

        for i in range(10):
            ret, frame = cap.read()

        cam_frames[camid] = frame.copy()

        cap.release()

    return cam_frames
예제 #5
0
    cv2.imshow(window, grid)

    while True:
        key = cv2.waitKey(10)

        if g_selected_cam is not None:
            break

        if key == 27:
            break

    cv2.destroyAllWindows()

    if g_selected_cam is not None:
        return list(cam_frames)[g_selected_cam]
    else:
        return list(cam_frames)[0]


if __name__ == '__main__':
    with open('config.yaml', 'r') as f:
        config = yaml.load(f, Loader=yaml.FullLoader)

    cam_frames = query_cameras(config['query_n_cams'])

    if cam_frames:
        selected_cam = select_camera(cam_frames)
        print(f"Selected camera {selected_cam}")
    else:
        log("No cameras are available")
예제 #6
0
def print_help():
    log('\n\n=== Control keys ===')
    log('1-9: Change avatar')
    log('W: Zoom camera in')
    log('S: Zoom camera out')
    log('A: Previous avatar in folder')
    log('D: Next avatar in folder')
    log('Q: Get random avatar')
    log('X: Calibrate face pose')
    log('I: Show FPS')
    log('ESC: Quit')
    log('\nFull key list: https://github.com/alievk/avatarify#controls')
    log('\n\n')
예제 #7
0
    log('X: Calibrate face pose')
    log('I: Show FPS')
    log('ESC: Quit')
    log('\nFull key list: https://github.com/alievk/avatarify#controls')
    log('\n\n')


if __name__ == "__main__":

    global display_string
    display_string = ""

    IMG_SIZE = 256

    if opt.no_stream:
        log('Force no streaming')
        _streaming = False

    log('Loading Predictor')
    predictor_args = {
        'config_path': opt.config,
        'checkpoint_path': opt.checkpoint,
        'relative': opt.relative,
        'adapt_movement_scale': opt.adapt_scale,
        'enc_downscale': opt.enc_downscale
    }
    if opt.is_worker:
        from afy import predictor_worker
        predictor_worker.run_worker(opt.worker_port)
        sys.exit(0)
    elif opt.worker_host:
예제 #8
0
import numpy as np
import cv2

from afy.videocaptureasync import VideoCaptureAsync
from afy.arguments import opt
from afy.utils import Once, log, crop, pad_img, resize, TicToc

from sys import platform as _platform
_streaming = False
if _platform == 'linux' or _platform == 'linux2':
    import pyfakewebcam
    _streaming = True

if _platform == 'darwin':
    if opt.worker_host is None:
        log('\nOnly remote GPU mode is supported for Mac (use --worker-host option to connect to the server)'
            )
        log('Standalone version will be available lately!\n')
        exit()


def is_new_frame_better(source, driving, precitor):
    global avatar_kp
    global display_string

    if avatar_kp is None:
        display_string = "No face detected in avatar."
        return False

    if predictor.get_start_frame() is None:
        display_string = "No frame to compare to."
        return True