advancedskrald/adapter.py

29 lines
678 B
Python

import base64
import json
import cv2
import sys
import numpy as np
from runner import warp_board
# Load base64 encoded image from stdin
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.IMREAD_COLOR)
# Warp board, saving the homography points as well
src_points = dst_points = []
warped = warp_board(camera_img, src_points=src_points, dst_points=dst_points)
# Finally, output to stdout for unity to read
result = {
"src_points": [p.tolist() for p in src_points],
"dst_points": [p.tolist() for p in dst_points],
}
print(json.dumps(result))