Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NdlS 2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AR_Sandbox
NdlS 2024
Commits
624e67e9
Commit
624e67e9
authored
3 months ago
by
kevin.heirich
Browse files
Options
Downloads
Patches
Plain Diff
Code cleaning
parent
fe6552ef
No related branches found
No related tags found
1 merge request
!1
2024
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
demo.py
+7
-52
7 additions, 52 deletions
demo.py
sandbox_conf.yaml
+2
-2
2 additions, 2 deletions
sandbox_conf.yaml
sandbox_conf_backup.yaml
+27
-0
27 additions, 0 deletions
sandbox_conf_backup.yaml
with
36 additions
and
54 deletions
demo.py
+
7
−
52
View file @
624e67e9
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...
'
)
...
...
This diff is collapsed.
Click to expand it.
sandbox_conf.yaml
+
2
−
2
View file @
624e67e9
...
...
@@ -3,8 +3,8 @@ AdjustingMatrix:
angle
:
0.5
width
:
3
height
:
2
matrix
:
[
1.0
,
0
,
50
,
-0
,
1
,
5
0
]
#matrix: [
0.999696374, 0.0246404037
, 0, -0
.0246404037, 0.999696374
, 0]
matrix
:
[
1.0
,
0
,
50
,
-0
,
1
,
7
0
]
#matrix: [
1.0, 0
,
5
0, -0
, 1
,
5
0]
# [?, rotation, ?, ?, ?, ?]
#angle: 0
#width: 3
...
...
This diff is collapsed.
Click to expand it.
sandbox_conf_backup.yaml
0 → 100644
+
27
−
0
View file @
624e67e9
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment