advancedskrald/adapter.py
2019-04-17 18:20:37 +02:00

26 lines
611 B
Python

import base64
import json
import sys
import cv2
import numpy as np
from runner import find_homography
# 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.COLOR_BGR2RGB)
camera_img = cv2.cvtColor(camera_img, cv2.COLOR_BGR2RGB)
# Find keypoints in image and pass them back to unity
homography = find_homography(camera_img)
# Finally, output to stdout for unity to read
result = {
"homography": homography.tolist(),
}
print(json.dumps(result))