Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
AVVR-Pipeline-GDP4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
GDP Project 4
AVVR-Pipeline-GDP4
Commits
613e29d7
Commit
613e29d7
authored
5 months ago
by
tee1g21
Browse files
Options
Downloads
Patches
Plain Diff
First attempt and actual depth2disparity conversion
parent
a4b2f58e
No related branches found
No related tags found
1 merge request
!15
GDP_4.4.6-Depth2Disparity
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/Depth2Disparity/depth2disparity.py
+38
-12
38 additions, 12 deletions
scripts/Depth2Disparity/depth2disparity.py
with
38 additions
and
12 deletions
scripts/Depth2Disparity/depth2disparity.py
+
38
−
12
View file @
613e29d7
...
...
@@ -5,6 +5,7 @@
import
argparse
import
numpy
as
np
import
cv2
def
relative2abs
(
rel_depth_map
,
coord1
,
dist1
,
coord2
,
dist2
):
...
...
@@ -22,19 +23,44 @@ def relative2abs(rel_depth_map, coord1, dist1, coord2, dist2):
# this should not be normalised, the values in the array should equate to literal distances
return
abs_depth_map
def
depth2disparity
(
_abs_depth_map
):
# Calculate disparity map from depth map
# random values
baseline
=
0.54
# Baseline distance in meters
focal_length
=
0.05
# Focal length in meters
# Calculate disparity map
disparity_map
=
baseline
*
focal_length
/
_abs_depth_map
# normalise disparity map between 0 and 255
disparity_map
=
(
disparity_map
-
disparity_map
.
min
())
/
(
disparity_map
.
max
()
-
disparity_map
.
min
())
*
255
def
depth2disparity
(
abs_depth_map
,
baseline
=
0.176
,
disp_scale
=
2.0
,
disp_offset
=-
120
):
# Get image dimensions
height
,
width
=
abs_depth_map
.
shape
# Calculate angular coordinates for each pixel
unit_w
=
2.0
/
width
# Longitude step size
unit_h
=
1.0
/
height
# Latitude step size
# Initialize disparity map
disparity_map
=
np
.
zeros_like
(
abs_depth_map
,
dtype
=
np
.
float32
)
for
i
in
range
(
height
):
theta_t
=
i
*
unit_h
*
np
.
pi
# Latitude angle for the row
for
j
in
range
(
width
):
# Longitude angle (not strictly needed for disparity calculation)
phi
=
j
*
unit_w
*
np
.
pi
# Retrieve the absolute depth (r_t) for this pixel
r_t
=
abs_depth_map
[
i
,
j
]
# Avoid division by zero for invalid or infinite depth values
if
r_t
<=
0
:
disparity_map
[
i
,
j
]
=
0
continue
# Calculate angular disparity (d) using the spherical depth-to-disparity formula
try
:
angle_disp
=
np
.
arctan
(
baseline
/
(
r_t
*
np
.
sin
(
theta_t
)
+
r_t
*
np
.
cos
(
theta_t
)
*
np
.
tan
(
theta_t
))
)
-
theta_t
# Convert angular disparity to pixel disparity
disparity_map
[
i
,
j
]
=
(
angle_disp
/
(
unit_h
*
np
.
pi
)
-
disp_offset
)
*
disp_scale
except
ZeroDivisionError
:
disparity_map
[
i
,
j
]
=
0
return
disparity_map
...
...
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