advancedskrald/adapter.py

27 lines
686 B
Python
Raw Normal View History

import base64
2019-04-11 11:39:19 +00:00
import json
2019-04-16 21:29:41 +00:00
import sys
2019-04-11 11:39:19 +00:00
import cv2
import numpy as np
2019-04-16 21:29:41 +00:00
from runner import find_keypoints
2019-04-11 11:39:19 +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)
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
2019-04-16 21:29:41 +00:00
# Find keypoints in image and pass them back to unity
src_points, dst_points = find_keypoints(camera_img)
2019-04-11 11:39:19 +00:00
# Finally, output to stdout for unity to read
result = {
2019-04-16 21:29:41 +00:00
"src_points": [p.tolist() for p in src_points],
"dst_points": [p.tolist() for p in dst_points],
2019-04-11 11:39:19 +00:00
}
print(json.dumps(result))