2019-04-11 12:25:48 +00:00
|
|
|
import base64
|
2019-04-11 11:39:19 +00:00
|
|
|
import json
|
|
|
|
|
|
|
|
import cv2
|
2019-04-11 12:25:48 +00:00
|
|
|
import sys
|
2019-04-11 11:39:19 +00:00
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from runner import warp_board
|
|
|
|
|
|
|
|
|
2019-04-11 12:25:48 +00:00
|
|
|
# Load base64 encoded image from stdin
|
|
|
|
stdin = sys.stdin.readline()
|
|
|
|
stdin_decoded = base64.b64decode(stdin)
|
|
|
|
img_array = np.frombuffer(stdin_decoded, dtype=np.uint8)
|
2019-04-16 12:10:36 +00:00
|
|
|
camera_img = cv2.imdecode(img_array, flags=cv2.COLOR_BGR2RGB)
|
|
|
|
camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB)
|
2019-04-11 11:39:19 +00:00
|
|
|
|
|
|
|
# Warp board, saving the homography points as well
|
2019-04-11 12:25:48 +00:00
|
|
|
src_points = dst_points = []
|
2019-04-16 12:10:36 +00:00
|
|
|
#cv2.imshow("ppslpsl", camera_img)
|
|
|
|
#cv2.waitKey(0)
|
2019-04-11 11:39:19 +00:00
|
|
|
|
2019-04-16 12:10:36 +00:00
|
|
|
points1, points2 = warp_board(camera_img, src_points=src_points, dst_points=dst_points, short_circuit=True)
|
2019-04-11 11:39:19 +00:00
|
|
|
|
|
|
|
# Finally, output to stdout for unity to read
|
|
|
|
result = {
|
2019-04-16 12:10:36 +00:00
|
|
|
"src_points": [p.tolist() for p in points1],
|
|
|
|
"dst_points": [p.tolist() for p in points2],
|
2019-04-11 11:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
print(json.dumps(result))
|