Exemplo n.º 1
0
def process_video():
    # net initialize
    net = ailia.Net(MODEL_PATH, WEIGHT_PATH, env_id=args.env_id)

    if args.face_recognition:
        locator = FaceLocator()
    else:
        locator = None

    capture = webcamera_utils.get_capture(args.video)
    if args.savepath != SAVE_IMAGE_PATH:
        writer = webcamera_utils.get_writer(args.savepath, args.resolution,
                                            args.resolution)
    else:
        writer = None

    while (True):
        ret, frame = capture.read()
        if (cv2.waitKey(1) & 0xFF == ord('q')) or not ret:
            break

        img = process_frame(net, locator, frame)

        img = img[..., ::-1]
        cv2.imshow('frame', img)
        # save results
        if writer is not None:
            writer.write(img)

    capture.release()
    cv2.destroyAllWindows()
    if writer is not None:
        writer.release()
    logger.info('Script finished successfully.')
Exemplo n.º 2
0
def process_video():
    # net initialize
    env_id = ailia.get_gpu_environment_id()
    print(f'env_id: {env_id}')
    net = ailia.Net(MODEL_PATH, WEIGHT_PATH, env_id=env_id)

    if args.face_recognition:
        locator = FaceLocator()
    else:
        locator = None

    if args.video == '0':
        print('[INFO] Webcam mode is activated')
        capture = cv2.VideoCapture(0)
        if not capture.isOpened():
            print("[ERROR] webcamera not found")
            sys.exit(1)
    else:
        if check_file_existance(args.video):
            capture = cv2.VideoCapture(args.video)

    while (True):
        ret, frame = capture.read()
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        if not ret:
            continue

        img = process_frame(net, locator, frame)

        cv2.imshow('frame', img[..., ::-1])

    capture.release()
    cv2.destroyAllWindows()
    print('Script finished successfully.')
Exemplo n.º 3
0
def transform_image():
    """Full transormation on a single image loaded from filepath in arguments.
    """
    net = ailia.Net(MODEL_PATH, WEIGHT_PATH, env_id=args.env_id)

    # input image loop
    for image_path in args.input:
        # prepare input data
        logger.info(image_path)
        image = cv2.imread(image_path)

        if args.face_recognition:
            locator = FaceLocator()
        else:
            locator = None

        logger.info('Start inference...')

        if args.benchmark:
            logger.info('BENCHMARK mode')
            for i in range(5):
                start = int(round(time.time() * 1000))

                out_image = process_frame(net, locator, image)

                end = int(round(time.time() * 1000))
                logger.info(f'\tailia processing time {end - start} ms')

        else:
            out_image = process_frame(net, locator, image)

        savepath = get_savepath(args.savepath, image_path)
        logger.info(f'saved at : {savepath}')
        cv2.imwrite(savepath, out_image[..., ::-1])
    return True
Exemplo n.º 4
0
def transform_image():
    """Full transormation on a single image loaded from filepath in arguments."""
    image = cv2.imread(args.input)
    env_id = ailia.get_gpu_environment_id()
    print(f'env_id: {env_id}')

    net = ailia.Net(MODEL_PATH, WEIGHT_PATH, env_id=env_id)

    if args.face_recognition:
        locator = FaceLocator()
    else:
        locator = None

    if args.benchmark:
        print('BENCHMARK mode')
        for i in range(5):
            start = int(round(time.time() * 1000))

            out_image = process_frame(net, locator, image)

            end = int(round(time.time() * 1000))
            print(f'\tailia processing time {end - start} ms')

    else:
        out_image = process_frame(net, locator, image)

    cv2.imwrite(args.savepath, out_image[..., ::-1])
    return True