diff --git a/demo.py b/demo.py index 35a4a58e1fe6b46e23c5675e55704b78029a683a..0829b33e888570b123f05714cbb50fae7c47afc3 100644 --- a/demo.py +++ b/demo.py @@ -1,18 +1,5 @@ import falcon -# import json -# from ar_sandbox import Sandbox -# import sys -# import cv2 -# import numpy as np -# import numpy.ma as npma -# from esrimap.esrimap import EsriAscii -# from PIL import Image -# import requests -# import time -# import math - from ar_sandbox import Sandbox -# from ar_sandbox.wrapper import sandbox_wrapper as sw import sys import cv2 import numpy as np @@ -24,17 +11,13 @@ import time import math import json - - NORMALIZATION_BETWEEN = (0.8, 1.2) LO_NORM = NORMALIZATION_BETWEEN[0] HI_NORM = NORMALIZATION_BETWEEN[1] - SHOW_LINES = True USE_HARD_COLORS = False LINE_COLORS = [255, 255, 255] - COLORS_FULL_SPECTRUM_SOFT = [ (0.2, (0, 0, 255)), (.25, (0, 255, 255)), @@ -117,19 +100,16 @@ class FakeSandbox: def start(self, *args): cap = cv2.VideoCapture(0) while cap.isOpened(): - # im = Image.open("test_aru.png") ret, fr = cap.read() frame = cv2.resize(fr, (588, 432)) mat = np.loadtxt("depth") - # mat = cv2.cvtColor(fr, cv2.COLOR_BGR2GRAY) mat2 = frame if self.on_frame is not None: frame = self.on_frame(mat, mat2) cv2.imshow("frame", frame) - # time.sleep(self.refresh // 1000) k = cv2.waitKey(self.refresh) if k == 27: break @@ -148,16 +128,7 @@ def get_color(depth, hard_colors=False) -> np.ndarray: A 3 channel BGR matrix of the same size as depth_matrix. """ depth_matrix = depth.copy() - # if hard_colors: - # pts = POINTS_HARD - # r = COLOR_R_HARD - # g = COLOR_G_HARD - # b = COLOR_B_HARD - # else: - # pts = POINTS - # r = COLOR_R - # g = COLOR_G - # b = COLOR_B + if hard_colors: pts = COLORMAP_HARD[0] r = COLORMAP_HARD[1] @@ -170,11 +141,8 @@ def get_color(depth, hard_colors=False) -> np.ndarray: b = COLORMAP[3] r_val = np.interp(depth_matrix, pts, r) - # print(r_val) g_val = np.interp(depth_matrix, pts, g) - # print(g_val) b_val = np.interp(depth_matrix, pts, b) - # print(b_val) res = np.dstack((b_val, g_val, r_val)).astype(np.uint8) return res @@ -189,8 +157,6 @@ def display_level(frame): def send_request(body, url="http://localhost:8000/map"): - # with open("mapoutput.asc", "w") as fp: - # json.dump(fp, body) try: requests.post(url, json=body) except Exception as e: @@ -305,7 +271,7 @@ def make_esri_and_send(depth, color, *args): api_content_esri = esri_map.to_ascii() api_content_aruco = build_arucos_json(detected) # tags = build_arucos_json(detected) - # print(tags) + # with open("aruco_tags.json", "w") as fp: # json.dump(tags, fp) @@ -327,11 +293,9 @@ def get_center(corner): # TODO def detect_aruco(a, b=None, c=None): return def detect_aruco(frame, - #aruco_dict=cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50), - #aruco_params=cv2.aruco.DetectorParameters_create()): aruco_dict=cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_4X4_50), aruco_params=cv2.aruco.DetectorParameters()): - output = frame.copy() + # output = frame.copy() #(corners, ids, rejected) = cv2.aruco.detectMarkers(frame, aruco_dict, parameters=aruco_params) detector = cv2.aruco.ArucoDetector(aruco_dict, aruco_params) @@ -344,14 +308,13 @@ def detect_aruco(frame, ctr = get_center(corners[c]) top_left = corners[c][0][0] centers.append(get_center(corners[c])) - # print("Corner is", corners[c], "Center is", get_center(corners[c])) (w1, w2) = [-1, -1] (v1, v2) = top_left - ctr rotation_in_degree = math.degrees(math.atan2(w2 * v1 - w1 * v2, w1 * v1 + w2 * v2)) rotations.append(round(rotation_in_degree, 2)) except Exception as e: print(e) - return output, (corners, ids, rejected), centers, rotations + return None, (corners, ids, rejected), centers, rotations def save_matrices(depth, frame, *args): @@ -406,6 +369,7 @@ class ApiEsri: class ApiAruco: def on_get(self, req, resp): + # resp.media = json.dumps(api_content_aruco) resp.media = api_content_aruco @@ -425,20 +389,13 @@ def main(): COLORMAP_HARD = create_colormap(create_hard_colors(cmap)) SHOW_LINES = False - #if arguments.lines: - # SHOW_LINES = True - USE_HARD_COLORS = False - #if arguments.hard: - # USE_HARD_COLORS = True # colours = [(.2, (0,0,128)), (.25, (68, 87, 227)), (.3, (236, 255, 89)),(.4, (67, 138, 65)),(.6, (128,128,128)), (.8, (255, 255, 255))] # colours = [(.2, (128,0,0)),(.3, (255,0,0)),(.4, (255,255,255)), (.5, (0,0,255)), (.6,(0, 0, 128))] # COLORMAP = create_colormap(color_array=colours) # COLORMAP_HARD = create_colormap(create_hard_colors(colours)) - # USE_HARD_COLORS=True - LINE_COLORS = [0,0,0] box = Sandbox(refresh=1000) box.verbosity = 5 @@ -446,20 +403,18 @@ def main(): box.on_frame = make_esri_and_send box.start(box) - +# ---- MAIN ---- from wsgiref.simple_server import make_server - - from threading import Thread app = falcon.App() app.add_route('/sandbox', ApiEsri()) app.add_route('/aruco', ApiAruco()) - class ApiThread(Thread): def run(self): + print("run") with make_server('', 8000, app) as httpd: print('Serving on port 8000...') diff --git a/sandbox_conf.yaml b/sandbox_conf.yaml index e2c06e3181c52fe40ef454f71ec887ff655cdd1d..a59661043208415b2ddfe2ac04d13cd7c0494fa2 100644 --- a/sandbox_conf.yaml +++ b/sandbox_conf.yaml @@ -3,8 +3,8 @@ AdjustingMatrix: angle: 0.5 width: 3 height: 2 - matrix: [1.0, 0, 50, -0, 1, 50] - #matrix: [0.999696374, 0.0246404037, 0, -0.0246404037, 0.999696374, 0] + matrix: [1.0, 0, 50, -0, 1, 70] + #matrix: [1.0, 0, 50, -0, 1, 50] # [?, rotation, ?, ?, ?, ?] #angle: 0 #width: 3 diff --git a/sandbox_conf_backup.yaml b/sandbox_conf_backup.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4a32850888b9e5c1bd6451e6af0b746fc86de00d --- /dev/null +++ b/sandbox_conf_backup.yaml @@ -0,0 +1,27 @@ +AdjustingMatrix: + angle: 1.4119340386036046 + width: 3 + height: 2 + matrix: [0.999696374, 0.0246404037, 0, -0.0246404037, 0.999696374, 0] +DistanceTopSandbox: + distance: 1 +CroppingMask: + x: 52 + y: 19 + width: 588 # 568 + height: 432 +BeamerResolution: + width: 1280 + height: 1024 +BeamerPosition: + x: 0.0536931753 + y: 0.260815978 + z: -0.325273067 +FrameProcessProfil: + contrast: 1.0900000000000001 + brightness: 14 + minDistance: 15 + cannyEdgeThreshold: 184 + houghAccThreshold: 35 + minRadius: 0 + maxRadius: 0