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
250a6859
Commit
250a6859
authored
Feb 27, 2020
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup:
+ hardcoded constants + comments and docs
parent
567495ea
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
+23
-20
blender_generate_image_and_depth.py
blender_generate_image_and_depth.py
+23
-20
No files found.
blender_generate_image_and_depth.py
View file @
250a6859
...
@@ -2,24 +2,28 @@
...
@@ -2,24 +2,28 @@
Copyright (C) 2020, Elphel Inc.
Copyright (C) 2020, Elphel Inc.
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: GPL-3.0-or-later
Author: Oleg K Dzhimiev <oleg@elphel.com>
Author: Oleg K Dzhimiev <oleg@elphel.com>
'''
'''
Usage:
Usage:
~$ blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN
~$ blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN
or
or
~$ <path-to-blender>/blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN
~$ <path-to-blender>/blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN
- file names must include path
Notes:
- must be .obj format
- *.obj format
- at the same path all accompanying files must be present - .mtl and textures
- include path in the *.obj name
- no space after commas
- unique *.obj names - everything is dumped into a single folder
- .mtl and textures, if exist, must be in the *.obj path
- no spaces after commas in the file list
- blender executable must be in the path
- blender executable must be in the path
- ~$ which blender
- ~$ which blender
- alternatively can call from blender path
- alternatively can call from blender path
Example:
Example:
~$ blender -b -P blender_generate_image_and_depth.py --
input/1527256815_550165_v01/1527256815_550165.obj,input/1527256858_750165_v01/1527256858_750165
.obj
~$ blender -b -P blender_generate_image_and_depth.py --
path1/model1.obj,path2/model2
.obj
Output:
Output:
...
@@ -32,21 +36,28 @@ Comment:
...
@@ -32,21 +36,28 @@ Comment:
- didn't work for some models in Blender v2.82.7
- didn't work for some models in Blender v2.82.7
'''
'''
import
numpy
as
np
import
numpy
as
np
import
os
import
os
import
sys
import
sys
import
bpy
import
bpy
# hardcoded constants
img_w
=
2592
img_h
=
1902
img_fov_degs
=
66.8
model_default_rotation
=
(
90
*
np
.
pi
/
180.0
,
0
,
0
)
model_output_folder
=
"output"
model_output_folder
=
"output"
# end constants
scene
=
bpy
.
context
.
scene
scene
=
bpy
.
context
.
scene
world
=
scene
.
world
world
=
scene
.
world
camera
=
scene
.
camera
camera
=
scene
.
camera
scene
.
render
.
resolution_x
=
2592
# fixed resolution for now
scene
.
render
.
resolution_y
=
1902
scene
.
render
.
resolution_x
=
img_w
scene
.
render
.
resolution_y
=
img_h
scene
.
render
.
resolution_percentage
=
100
scene
.
render
.
resolution_percentage
=
100
world
.
use_nodes
=
False
world
.
use_nodes
=
False
...
@@ -58,10 +69,10 @@ objs.remove(objs["Light"], do_unlink=True)
...
@@ -58,10 +69,10 @@ objs.remove(objs["Light"], do_unlink=True)
camera
.
location
=
(
0
,
0
,
0
)
camera
.
location
=
(
0
,
0
,
0
)
camera
.
rotation_mode
=
"XYZ"
camera
.
rotation_mode
=
"XYZ"
camera
.
rotation_euler
=
(
90
*
np
.
pi
/
180.0
,
0
,
0
)
camera
.
rotation_euler
=
model_default_rotation
camera
.
data
.
clip_end
=
10000
camera
.
data
.
clip_end
=
10000
camera
.
data
.
clip_start
=
0.1
camera
.
data
.
clip_start
=
0.1
camera
.
data
.
angle
=
66.8
*
np
.
pi
/
180
camera
.
data
.
angle
=
img_fov_degs
*
np
.
pi
/
180
bpy
.
context
.
scene
.
use_nodes
=
True
bpy
.
context
.
scene
.
use_nodes
=
True
...
@@ -69,6 +80,7 @@ rn = scene.node_tree.nodes.new('CompositorNodeRLayers')
...
@@ -69,6 +80,7 @@ rn = scene.node_tree.nodes.new('CompositorNodeRLayers')
depth
=
scene
.
node_tree
.
nodes
.
new
(
'CompositorNodeOutputFile'
)
depth
=
scene
.
node_tree
.
nodes
.
new
(
'CompositorNodeOutputFile'
)
depth
.
format
.
file_format
=
'OPEN_EXR'
depth
.
format
.
file_format
=
'OPEN_EXR'
depth
.
format
.
color_depth
=
'32'
depth
.
format
.
color_depth
=
'32'
# TODO: try BW
depth
.
format
.
color_mode
=
'RGB'
depth
.
format
.
color_mode
=
'RGB'
depth
.
format
.
exr_codec
=
'ZIP'
depth
.
format
.
exr_codec
=
'ZIP'
depth
.
base_path
=
model_output_folder
depth
.
base_path
=
model_output_folder
...
@@ -78,21 +90,12 @@ scene.node_tree.links.new(rn.outputs[2], depth.inputs[0])
...
@@ -78,21 +90,12 @@ scene.node_tree.links.new(rn.outputs[2], depth.inputs[0])
fpaths
=
sys
.
argv
[
-
1
]
.
split
(
','
)
fpaths
=
sys
.
argv
[
-
1
]
.
split
(
','
)
TEST
=
False
if
(
TEST
):
fpaths
=
[
'input/1527256815_550165_v01/1527256815_550165.obj'
,
'input/1527256903_350165/v03/1527256903_350165.obj'
,
'input/1488240695_710844_x3d105/1488240695_710844.obj'
]
print
(
fpaths
)
if
(
not
(
os
.
path
.
isdir
(
model_output_folder
))):
if
(
not
(
os
.
path
.
isdir
(
model_output_folder
))):
os
.
mkdir
(
model_output_folder
)
os
.
mkdir
(
model_output_folder
)
for
fpath
in
fpaths
:
for
fpath
in
fpaths
:
obj_name
=
fpath
.
split
(
'/'
)[
-
1
][:
-
4
]
obj_name
=
fpath
.
split
(
'/'
)[
-
1
][:
-
4
]
print
(
obj_name
)
bpy
.
ops
.
import_scene
.
obj
(
filepath
=
fpath
,
use_smooth_groups
=
False
)
bpy
.
ops
.
import_scene
.
obj
(
filepath
=
fpath
,
use_smooth_groups
=
False
)
...
...
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