Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
ar_sandbox_python
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
ar_sandbox_python
Commits
0da6c504
Commit
0da6c504
authored
3 years ago
by
Alexis Durgnat
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup examples, optimize a little
parent
2b5d693b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/ar_sandbox/examples/examples.py
+32
-25
32 additions, 25 deletions
src/ar_sandbox/examples/examples.py
with
32 additions
and
25 deletions
src/ar_sandbox/examples/examples.py
+
32
−
25
View file @
0da6c504
from
typing
import
Any
import
numpy
as
np
import
numpy
as
np
COLORS
=
[
COLORS
=
[
(
0
,
[
255
,
0
,
0
]
),
(
0
,
(
255
,
0
,
0
)
),
(
0.25
,
[
255
,
255
,
0
]
),
(
0.25
,
(
255
,
255
,
0
)
),
(
0.5
,
[
0
,
255
,
0
]
),
(
0.5
,
(
0
,
255
,
0
)
),
(
0.75
,
[
0
,
255
,
255
]
),
(
0.75
,
(
0
,
255
,
255
)
),
(
1
,
[
0
,
0
,
255
]
)
(
1
,
(
0
,
0
,
255
)
)
]
]
class
LevelDisplay
():
class
LevelDisplay
():
@staticmethod
def
__init__
(
self
,
colormap
:
list
=
COLORS
)
->
None
:
def
get_color
(
depth_matrix
,
frame
,
draw_lines
=
True
,
colormap
=
COLORS
):
"""
"""
Given a depth matrix between 0-1, return a color from
a given colormap.
Inialize the level display with
a given colormap.
The colormap is a list of tuples containing the depth value, and the
The colormap is a list of tuples containing the depth value, and the
color for this level :
color for this level :
(depth_value,
[
RedVal, GreenVal, BlueVal
]
)
(depth_value,
(
RedVal, GreenVal, BlueVal
)
)
The colormap should at least contain a color for the depths 0 and 1.
The colormap should at least contain a color for the depths 0 and 1.
See COLORS for an example colormap.
See COLORS for an example colormap.
Arguments:
colormap : A list of tuple representing a mapping between a float value and
a triple of Red, Green and Blue values.
"""
self
.
colormap
=
colormap
self
.
points
=
np
.
array
([
c
[
0
]
for
c
in
colormap
])
self
.
r
=
[
c
[
1
][
0
]
for
c
in
colormap
]
self
.
g
=
[
c
[
1
][
1
]
for
c
in
colormap
]
self
.
b
=
[
c
[
1
][
2
]
for
c
in
colormap
]
def
__call__
(
self
,
*
args
:
Any
,
**
kwds
:
Any
)
->
Any
:
return
self
.
get_color
(
*
args
,
**
kwds
)
def
get_color
(
self
,
depth_matrix
:
np
.
ndarray
,
frame
:
np
.
ndarray
,
draw_lines
:
bool
=
True
)
->
np
.
ndarray
:
"""
Given a depth matrix between 0-1, return a color from the colormap
Arguments:
Arguments:
depth_matrix : Normalized 1 channel numpy matrix
depth_matrix : Normalized 1 channel numpy matrix
frame: Unused. The frame captured by the camera
frame: Unused. The frame captured by the camera
draw_line: Should line be drawn between levels ?
draw_line: Should line be drawn between levels ?
colormap: Override the default colormap.
Return:
Return:
A 3 channel matrix in BGR frame of the same size as depth_matrix.
A 3 channel matrix in BGR frame of the same size as depth_matrix.
"""
"""
points
=
np
.
array
([
c
[
0
]
for
c
in
colormap
])
if
draw_lines
:
line_mask
=
LevelDisplay
.
draw_lines
(
depth_matrix
,
self
.
points
)
r
=
[
c
[
1
][
2
]
for
c
in
colormap
]
rval
=
np
.
interp
(
depth_matrix
,
self
.
points
,
self
.
r
)
g
=
[
c
[
1
][
1
]
for
c
in
colormap
]
gval
=
np
.
interp
(
depth_matrix
,
self
.
points
,
self
.
g
)
b
=
[
c
[
1
][
0
]
for
c
in
colormap
]
bval
=
np
.
interp
(
depth_matrix
,
self
.
points
,
self
.
b
)
# print(rval)
if
draw_lines
:
line_mask
=
LevelDisplay
.
draw_lines
(
depth_matrix
,
points
)
# print(line_mask.shape)
rval
=
np
.
interp
(
depth_matrix
,
points
,
r
)
gval
=
np
.
interp
(
depth_matrix
,
points
,
g
)
bval
=
np
.
interp
(
depth_matrix
,
points
,
b
)
res
=
np
.
dstack
((
bval
,
gval
,
rval
)).
astype
(
np
.
uint8
)
res
=
np
.
dstack
((
bval
,
gval
,
rval
)).
astype
(
np
.
uint8
)
if
draw_lines
:
res
[
line_mask
,:]
=
0
if
draw_lines
:
res
[
line_mask
,:]
=
0
return
res
return
res
@staticmethod
@staticmethod
def
draw_lines
(
depth
,
points
,
width
=
0.025
,
between_levels
=
False
):
def
draw_lines
(
depth
:
np
.
ndarray
,
points
:
list
,
width
:
float
=
0.025
,
between_levels
:
bool
=
False
)
->
np
.
ndarray
:
"""
"""
Given the depth matrix and a list of points, return a mask for every
Given the depth matrix and a list of points, return a mask for every
value near the points. If between_levels is set to True, mask in
value near the points. If between_levels is set to True, mask in
...
@@ -73,6 +82,4 @@ class LevelDisplay():
...
@@ -73,6 +82,4 @@ class LevelDisplay():
halfwidth
=
width
/
2
halfwidth
=
width
/
2
for
line
in
lines
:
for
line
in
lines
:
mask
=
np
.
where
(
np
.
logical_or
(
mask
,
np
.
logical_and
(
depth
>=
line
-
halfwidth
,
depth
<=
line
+
halfwidth
)),
True
,
False
)
mask
=
np
.
where
(
np
.
logical_or
(
mask
,
np
.
logical_and
(
depth
>=
line
-
halfwidth
,
depth
<=
line
+
halfwidth
)),
True
,
False
)
# rpos_mline = np.interp([rpos_mline])
# print(mask)
return
mask
return
mask
\ No newline at end of file
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