advancedskrald/adapter.py

26 lines
570 B
Python
Raw Normal View History

2019-04-11 11:39:19 +00:00
import json
import cv2
import numpy as np
from runner import warp_board
# Run this script as: 'python3 adapter.py < ~/Pictures/board.png' or pipe a binary image to stdin
# Load binary image from stdin
with open(0, "rb") as stdin:
array = np.frombuffer(stdin.read(), dtype='uint8')
camera_img = cv2.imdecode(array, flags=cv2.IMREAD_COLOR)
# Warp board, saving the homography points as well
points = []
warped = warp_board(camera_img, dst_points=points)
# Finally, output to stdout for unity to read
result = {
"points": points
}
print(json.dumps(result))