Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
obj2rgbd
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
obj2rgbd
Commits
c0fbf9a8
Commit
c0fbf9a8
authored
Feb 27, 2020
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments and path scanning
parent
b111e3b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
19 deletions
+56
-19
obj2rgbd.py
obj2rgbd.py
+56
-19
No files found.
obj2rgbd.py
View file @
c0fbf9a8
import
os
import
os
import
subprocess
import
subprocess
import
sys
PATH_TO_BLENDER
=
''
PATH_TO_BLENDER
=
''
# depth map scale, units in the generated depth map for RGB-D - 16-bit png
# depth map scale, units in the generated depth map for RGB-D - 16-bit png
#DMP = 1 # 1 m - range 0-65535 m
#DMP = 1 # 1 m - range 0-65535 m
#
DMP = 0.1 # 10 cm - range 0-6553.5 m
DMP
=
0.1
# 10 cm - range 0-6553.5 m
DMP
=
0.01
# 1 cm - range 0-655.35 m
#
DMP = 0.01 # 1 cm - range 0-655.35 m
#DMP = 0.001 # 1 mm - range 0-65.535 m
#DMP = 0.001 # 1 mm - range 0-65.535 m
fpaths
=
[
'input/1527256815_550165_v01/1527256815_550165.obj'
,]
model_input_folder
=
"input"
model_output_folder
=
"output"
fpaths
=
[]
try
:
model_input_folder
=
sys
.
argv
[
1
]
except
IndexError
:
# default value will be used
pass
try
:
DMP
=
float
(
sys
.
argv
[
2
])
except
IndexError
:
# default value will be used
pass
for
rs
,
ds
,
_
in
os
.
walk
(
model_input_folder
):
for
d
in
ds
:
for
rss
,
_
,
fss
in
os
.
walk
(
os
.
path
.
join
(
rs
,
d
)):
for
f
in
fss
:
if
f
.
endswith
(
'obj'
):
fpaths
.
append
(
os
.
path
.
join
(
rss
,
f
))
filelist
=
','
.
join
(
fpaths
)
filelist
=
','
.
join
(
fpaths
)
# this will run by Blender's bundled python
# this will run by Blender's bundled python
subprocess
.
run
(
os
.
path
.
join
(
PATH_TO_BLENDER
,
'blender'
)
+
" -b -P blender_generate_image_and_depth.py -- "
+
filelist
,
shell
=
True
)
subprocess
.
run
(
os
.
path
.
join
(
PATH_TO_BLENDER
,
'blender'
)
+
" -b -P blender_generate_image_and_depth.py -- "
+
filelist
,
shell
=
True
)
fname
=
'1527256815_550165-depth.exr'
print
(
"All RGB-Ds generated"
)
model_output_folder
=
"output"
fname
=
os
.
path
.
join
(
model_output_folder
,
fname
)
import
exr2png
as
e2p
import
exr2png
as
e2p
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
from
PIL
import
Image
from
PIL
import
Image
import
numpy
as
np
import
numpy
as
np
dmap
=
e2p
.
exr2arr
(
fname
)[:,:,
0
]
resoluton
=
""
# zero background
if
DMP
>=
1
:
if
dmap
.
dtype
==
'float32'
:
resolution
=
str
(
int
(
DMP
))
+
"m"
dmap
[
dmap
==
10000000000.0
]
=
0
elif
DMP
>=
0.01
:
resolution
=
str
(
int
(
DMP
*
100
))
+
"cm"
elif
DMP
>=
0.001
:
resolution
=
str
(
int
(
DMP
*
1000
))
+
"mm"
print
(
"Depth maps will be scaled to "
+
resolution
+
" resolution covering range from 0 to "
+
str
(
DMP
*
65535
)
+
" meters"
)
for
fpath
in
fpaths
:
model_name
=
fpath
.
split
(
'/'
)[
-
1
][:
-
4
]
exr_path
=
os
.
path
.
join
(
model_output_folder
,
model_name
+
"-depth-1m-float32.exr"
)
png_path
=
os
.
path
.
join
(
model_output_folder
,
model_name
+
"-depth-"
+
resolution
+
".png"
)
print
(
"Generating "
+
png_path
)
dmap
=
e2p
.
exr2arr
(
exr_path
)[:,:,
0
]
# zero background
if
dmap
.
dtype
==
'float32'
:
dmap
[
dmap
==
10000000000.0
]
=
0
dmap
=
dmap
/
DMP
dmap
=
dmap
/
DMP
dmap
[
dmap
>
65535
]
=
0
dmap
[
dmap
>
65535
]
=
0
im
=
Image
.
fromarray
(
dmap
.
astype
(
np
.
uint16
))
im
=
Image
.
fromarray
(
dmap
.
astype
(
np
.
uint16
))
im
.
save
(
os
.
path
.
join
(
model_output_folder
,
'model-depth.png'
)
)
im
.
save
(
png_path
)
plt
.
imshow
(
dmap
)
#plt.imshow(dmap)
plt
.
colorbar
()
#plt.colorbar()
plt
.
show
()
#plt.show()
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment