Skip to content
Snippets Groups Projects
Commit 720910b1 authored by Adrien Lescourt's avatar Adrien Lescourt
Browse files

Kevin stuff

parent 6d2792f9
No related branches found
No related tags found
1 merge request!12024
{"arucos": []}
\ No newline at end of file
# import json
# from ar_sandbox import Sandbox # 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 # from ar_sandbox.wrapper import sandbox_wrapper as sw
import sys import sys
import cv2 import cv2
...@@ -9,6 +22,14 @@ from PIL import Image ...@@ -9,6 +22,14 @@ from PIL import Image
import requests import requests
import time import time
import math 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) NORMALIZATION_BETWEEN = (0.8, 1.2)
...@@ -66,7 +87,6 @@ COLOR_B_HARD = [c[1][2] for c in COLORS_FULL_SPECTRUM_HARD] ...@@ -66,7 +87,6 @@ COLOR_B_HARD = [c[1][2] for c in COLORS_FULL_SPECTRUM_HARD]
COLORMAP = None COLORMAP = None
COLORMAP_HARD = None COLORMAP_HARD = None
DEFAULT_URL = "http://localhost:8000"
def try_and_ignore(ignore=Exception, default_value=0.0): def try_and_ignore(ignore=Exception, default_value=0.0):
...@@ -172,12 +192,15 @@ def display_level(frame): ...@@ -172,12 +192,15 @@ def display_level(frame):
def send_request(body, url="http://localhost:8000/map"): def send_request(body, url="http://localhost:8000/map"):
# with open("mapoutput.asc", "w") as fp:
# json.dump(fp, body)
try: try:
requests.post(url, json=body) requests.post(url, json=body)
except Exception as e: except Exception as e:
print(e) print(e)
# This is the older method that was used to transmit arucos over the network
def build_req_body(map, tag_list): def build_req_body(map, tag_list):
arucos = [] arucos = []
for t in tag_list: for t in tag_list:
...@@ -201,6 +224,29 @@ def build_req_body(map, tag_list): ...@@ -201,6 +224,29 @@ def build_req_body(map, tag_list):
return body 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): def normalize_array(array):
return (array - array.min())/(array.max() - array.min()) return (array - array.min())/(array.max() - array.min())
...@@ -241,16 +287,30 @@ def make_esri_and_send(depth, color, *args): ...@@ -241,16 +287,30 @@ def make_esri_and_send(depth, color, *args):
# Aruco detection # Aruco detection
grayscale_frame = cv2.cvtColor(color, cv2.COLOR_BGR2GRAY) 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 # Create map and tag dictionary
esri_map = EsriAscii.from_ndarray(depth) 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 it toward api
send_request(build_req_body(esri_map, detected), url=DEFAULT_URL) #send_request(build_req_body(esri_map, detected), url=DEFAULT_URL)
# May locally save the esri_map for dest in destinations:
# esri_map.to_file("depth_map_v2.asc") 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 value will be displayed on the beamer
return levels return levels
...@@ -266,12 +326,19 @@ def get_center(corner): ...@@ -266,12 +326,19 @@ def get_center(corner):
c0, _, c2, _ = corner[0] c0, _, c2, _ = corner[0]
return int(c0[0] + (c2[0]-c0[0]) // 2), int(c0[1] + (c2[1]-c0[1]) // 2) 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, def detect_aruco(frame,
aruco_dict=cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50), #aruco_dict=cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50),
aruco_params=cv2.aruco.DetectorParameters_create()): #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)
#(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 = [] centers = []
rotations = [] rotations = []
for c in range(len(corners)): for c in range(len(corners)):
...@@ -376,7 +443,8 @@ if __name__ == "__main__": ...@@ -376,7 +443,8 @@ if __name__ == "__main__":
# USE_HARD_COLORS=True # USE_HARD_COLORS=True
LINE_COLORS = [0,0,0] LINE_COLORS = [0,0,0]
box = FakeSandbox(refresh=1000) box = Sandbox(refresh=1000)
box.verbosity = 5
box.init() box.init()
box.on_frame = make_esri_and_send box.on_frame = make_esri_and_send
box.start(box) box.start(box)
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
AdjustingMatrix: AdjustingMatrix:
angle: 1.4119340386036046 #angle: 0.5119340386036046
angle: 0.5
width: 3 width: 3
height: 2 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: DistanceTopSandbox:
distance: 1 distance: 1.11300004
CroppingMask: CroppingMask:
x: 52 x: 52
y: 19 y: 19
width: 588 # 568 width: 588
height: 432 height: 437
BeamerResolution: BeamerResolution:
width: 1400 width: 1280
height: 1050 height: 1024
BeamerPosition: BeamerPosition:
x: 0.0536931753 x: -0.0419691354
y: 0.260815978 #x: -0.0419691354
z: -0.325273067 y: 0.238534391
z: -0.126809254
FrameProcessProfil: FrameProcessProfil:
contrast: 1.0900000000000001 contrast: 1.1200000000000001
brightness: 14 brightness: -148
minDistance: 15 minDistance: 100
cannyEdgeThreshold: 184 cannyEdgeThreshold: 86
houghAccThreshold: 35 houghAccThreshold: 44
minRadius: 0 minRadius: 2
maxRadius: 0 maxRadius: 14
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment