diff --git a/demo.py b/demo.py index 0829b33e888570b123f05714cbb50fae7c47afc3..1781f1d49c967d1253191109d1f0fc22dab8e10e 100644 --- a/demo.py +++ b/demo.py @@ -1,5 +1,6 @@ import falcon from ar_sandbox import Sandbox +from io import BytesIO import sys import cv2 import numpy as np @@ -86,6 +87,7 @@ parse_float = try_and_ignore(ValueError, 0.0)(float) api_content_esri = "" api_content_aruco = "" +api_content_unity_png = None class FakeSandbox: @@ -225,7 +227,8 @@ def normalize_array_between(array, lower_bound, higher_bound): def make_esri_and_send(depth, color, *args): - global api_content_esri, api_content_aruco + global api_content_esri, api_content_aruco, api_content_unity_png + if COLORMAP is None or COLORMAP_HARD is None: gen_global_default_cmaps() # Normalization step @@ -275,7 +278,15 @@ def make_esri_and_send(depth, color, *args): # with open("aruco_tags.json", "w") as fp: # json.dump(tags, fp) + if api_content_unity_png is not None: + cv2.resize(api_content_unity_png, (levels.shape[0], levels.shape[1])) + im_rgb = cv2.cvtColor(api_content_unity_png, cv2.COLOR_BGR2RGB) + # im_rgb = cv2.flip(im_rgb, 1) + # im_rgb = cv2.flip(im_rgb, 0) + + return im_rgb # Return value will be displayed on the beamer + print(f"levels {levels.shape}") return levels @@ -363,17 +374,25 @@ def rgb_to_hex(rgb): return '#%02x%02x%02x' % rgb -class ApiEsri: +class ApiUnity: def on_get(self, req, resp): resp.media = api_content_esri + def on_post(self, req, resp): + global api_content_unity_png + image_data = req.bounded_stream.read() + api_content_unity_png = np.array(Image.open(BytesIO(image_data))) + print(f"FROMPOST: {api_content_unity_png.shape}") + + resp.status = falcon.HTTP_200 + resp.media = {'message': 'Data received successfully'} + class ApiAruco: def on_get(self, req, resp): # resp.media = json.dumps(api_content_aruco) resp.media = api_content_aruco - -def main(): +def main(): arg_colors = "" if arg_colors != "": colours = [] @@ -409,7 +428,7 @@ from wsgiref.simple_server import make_server from threading import Thread app = falcon.App() -app.add_route('/sandbox', ApiEsri()) +app.add_route('/sandbox', ApiUnity()) app.add_route('/aruco', ApiAruco()) class ApiThread(Thread):