diff --git a/aruco_tags.json b/aruco_tags.json new file mode 100644 index 0000000000000000000000000000000000000000..d83d93e96459e7286ab610a4c7b2607195fba63e --- /dev/null +++ b/aruco_tags.json @@ -0,0 +1 @@ +{"arucos": []} \ No newline at end of file diff --git a/demo.py b/demo.py index ff3e7cd96eb7ec47769091ab25295062fac0c1f7..2caf956b2ae8f681da8c75a9adb0ba291586cc16 100644 --- a/demo.py +++ b/demo.py @@ -1,4 +1,17 @@ + +# 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 @@ -9,6 +22,14 @@ from PIL import Image import requests import time import math +import json + + +# EDIT ME +DEFAULT_URL = "http://172.30.255.2:8000/map" +DEFAULT_URL2 = "http://10.136.217.168:8000/map" + +destinations = [DEFAULT_URL] NORMALIZATION_BETWEEN = (0.8, 1.2) @@ -66,7 +87,6 @@ COLOR_B_HARD = [c[1][2] for c in COLORS_FULL_SPECTRUM_HARD] COLORMAP = None COLORMAP_HARD = None -DEFAULT_URL = "http://localhost:8000" def try_and_ignore(ignore=Exception, default_value=0.0): @@ -172,12 +192,15 @@ 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: print(e) +# This is the older method that was used to transmit arucos over the network def build_req_body(map, tag_list): arucos = [] for t in tag_list: @@ -201,6 +224,29 @@ def build_req_body(map, tag_list): return body +# This new method is basically a copy pasted version of the one above without the map +# Maybe both of them are not needed anymore +def build_arucos_json(tag_list): + arucos = [] + for t in tag_list: + print(t) + (x, y), id, r = t + (x, y) = (parse_int(x), parse_int(y)) + id = parse_int(id) + r = parse_float(r) + arucos.append({ + "tag_id": id, + "position": { + "x": x, + "y": y + }, + "rotation": r + }) + body = { + "arucos": arucos + } + return body + def normalize_array(array): return (array - array.min())/(array.max() - array.min()) @@ -241,16 +287,30 @@ def make_esri_and_send(depth, color, *args): # Aruco detection grayscale_frame = cv2.cvtColor(color, cv2.COLOR_BGR2GRAY) - _, (corn, ids, rej), centers, rots = detect_aruco(grayscale_frame) + + _, (corn, ids, rej), centers, rots = detect_aruco(grayscale_frame) #TODO # Create map and tag dictionary esri_map = EsriAscii.from_ndarray(depth) - detected = build_tag_list(ids, centers, rots) + detected = build_tag_list(ids, centers, rots) #TODO # Send it toward api - send_request(build_req_body(esri_map, detected), url=DEFAULT_URL) - # May locally save the esri_map - # esri_map.to_file("depth_map_v2.asc") + #send_request(build_req_body(esri_map, detected), url=DEFAULT_URL) + for dest in destinations: + pass + #TODO + #send_request(build_req_body(esri_map, detected), url=dest) + #send_request(build_req_body(esri_map, []), url=dest) + #send_request(build_req_body(esri_map, detected), url=DEFAULT_URL2) + + + # May locally save the esri_map & arucos + esri_map.to_file("depth_map.asc") + tags = build_arucos_json(detected) + print(tags) + with open("aruco_tags.json", "w") as fp: + json.dump(tags, fp) + # Return value will be displayed on the beamer return levels @@ -266,12 +326,19 @@ def get_center(corner): c0, _, c2, _ = corner[0] return int(c0[0] + (c2[0]-c0[0]) // 2), int(c0[1] + (c2[1]-c0[1]) // 2) +# 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.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() - (corners, ids, rejected) = cv2.aruco.detectMarkers(frame, aruco_dict, parameters=aruco_params) + + #(corners, ids, rejected) = cv2.aruco.detectMarkers(frame, aruco_dict, parameters=aruco_params) + detector = cv2.aruco.ArucoDetector(aruco_dict, aruco_params) + (corners, ids, rejected) = detector.detectMarkers(frame) + centers = [] rotations = [] for c in range(len(corners)): @@ -376,7 +443,8 @@ if __name__ == "__main__": # USE_HARD_COLORS=True LINE_COLORS = [0,0,0] - box = FakeSandbox(refresh=1000) + box = Sandbox(refresh=1000) + box.verbosity = 5 box.init() box.on_frame = make_esri_and_send box.start(box) diff --git a/env.sh b/env.sh index c58ef142030d2ead41f1f46f3b9cda323b7fc5c9..5cef6089bc5515a761151f95691a7fb24c690ae0 100644 --- a/env.sh +++ b/env.sh @@ -1 +1,2 @@ -export LD_LIBRARY_PATH=/home/alexis/sandbox/sandbox_docker-builder/build/lib/ +#export LD_LIBRARY_PATH=/home/alexis/sandbox/sandbox_docker-builder/build/lib/ +export LD_LIBRARY_PATH=/home/sandbox/Documents/ar_sandbox_lib/build diff --git a/sandbox_conf.yaml b/sandbox_conf.yaml index 9fa6ebd2d61e28205719b28168e50d0078888247..e2c06e3181c52fe40ef454f71ec887ff655cdd1d 100644 --- a/sandbox_conf.yaml +++ b/sandbox_conf.yaml @@ -1,27 +1,35 @@ AdjustingMatrix: - angle: 1.4119340386036046 + #angle: 0.5119340386036046 + angle: 0.5 width: 3 height: 2 - matrix: [0.999696374, 0.0246404037, 0, -0.0246404037, 0.999696374, 0] + matrix: [1.0, 0, 50, -0, 1, 50] + #matrix: [0.999696374, 0.0246404037, 0, -0.0246404037, 0.999696374, 0] + # [?, rotation, ?, ?, ?, ?] + #angle: 0 + #width: 3 + #height: 2 + #matrix: [1, 0, 0, -0, 1, 0] DistanceTopSandbox: - distance: 1 + distance: 1.11300004 CroppingMask: x: 52 y: 19 - width: 588 # 568 - height: 432 + width: 588 + height: 437 BeamerResolution: - width: 1400 - height: 1050 + width: 1280 + height: 1024 BeamerPosition: - x: 0.0536931753 - y: 0.260815978 - z: -0.325273067 + x: -0.0419691354 + #x: -0.0419691354 + y: 0.238534391 + z: -0.126809254 FrameProcessProfil: - contrast: 1.0900000000000001 - brightness: 14 - minDistance: 15 - cannyEdgeThreshold: 184 - houghAccThreshold: 35 - minRadius: 0 - maxRadius: 0 + contrast: 1.1200000000000001 + brightness: -148 + minDistance: 100 + cannyEdgeThreshold: 86 + houghAccThreshold: 44 + minRadius: 2 + maxRadius: 14