From cde518c14e2586dabf71309855be7ffbdfcbcd09 Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Wed, 24 Apr 2019 09:41:57 +0200 Subject: [PATCH] Gonna catch em all. --- adapter.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/adapter.py b/adapter.py index f169448c..3ae0b668 100644 --- a/adapter.py +++ b/adapter.py @@ -7,26 +7,29 @@ import numpy as np from main import find_occupied_squares from runner import find_homography, warp_board -# Load base64 encoded image from stdin from tensor_classifier import predict_board + while True: - stdin = sys.stdin.readline() - stdin_decoded = base64.b64decode(stdin) - img_array = np.frombuffer(stdin_decoded, dtype=np.uint8) - camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB) - camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB) + try: + stdin = sys.stdin.readline() + stdin_decoded = base64.b64decode(stdin) + img_array = np.frombuffer(stdin_decoded, dtype=np.uint8) + camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB) + camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB) - # def do_everything: - homography = find_homography(camera_img) - warped_board = warp_board(camera_img, homography) - occupied_squares = find_occupied_squares(warped_board) - board = predict_board(occupied_squares) + # def do_everything: + homography = find_homography(camera_img) + warped_board = warp_board(camera_img, homography) + occupied_squares = find_occupied_squares(warped_board) + board = predict_board(occupied_squares) - # Finally, output to stdout for unity to read - result = { - "homography": homography.tolist(), - "board": board.to_array, - } + # Finally, output to stdout for unity to read + result = { + "homography": homography.tolist(), + "board": board.to_array, + } - print(json.dumps(result)) + print(json.dumps(result)) + except Exception as e: + print(e)