Loading blender_generate_image_and_depth.py +23 −20 Original line number Diff line number Diff line Loading @@ -2,24 +2,28 @@ Copyright (C) 2020, Elphel Inc. SPDX-License-Identifier: GPL-3.0-or-later Author: Oleg K Dzhimiev <oleg@elphel.com> ''' ''' Usage: ~$ blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN or ~$ <path-to-blender>/blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN - file names must include path - must be .obj format - at the same path all accompanying files must be present - .mtl and textures - no space after commas Notes: - *.obj format - include path in the *.obj name - 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 - ~$ which blender - alternatively can call from blender path 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: Loading @@ -32,21 +36,28 @@ Comment: - didn't work for some models in Blender v2.82.7 ''' import numpy as np import os import sys 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" # end constants scene = bpy.context.scene world = scene.world camera = scene.camera scene.render.resolution_x = 2592 scene.render.resolution_y = 1902 # fixed resolution for now scene.render.resolution_x = img_w scene.render.resolution_y = img_h scene.render.resolution_percentage = 100 world.use_nodes = False Loading @@ -58,10 +69,10 @@ objs.remove(objs["Light"], do_unlink=True) camera.location = (0,0,0) 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_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 Loading @@ -69,6 +80,7 @@ rn = scene.node_tree.nodes.new('CompositorNodeRLayers') depth = scene.node_tree.nodes.new('CompositorNodeOutputFile') depth.format.file_format = 'OPEN_EXR' depth.format.color_depth = '32' # TODO: try BW depth.format.color_mode = 'RGB' depth.format.exr_codec = 'ZIP' depth.base_path = model_output_folder Loading @@ -78,21 +90,12 @@ scene.node_tree.links.new(rn.outputs[2], depth.inputs[0]) 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))): os.mkdir(model_output_folder) for fpath in fpaths: obj_name = fpath.split('/')[-1][:-4] print(obj_name) bpy.ops.import_scene.obj(filepath=fpath, use_smooth_groups=False) Loading Loading
blender_generate_image_and_depth.py +23 −20 Original line number Diff line number Diff line Loading @@ -2,24 +2,28 @@ Copyright (C) 2020, Elphel Inc. SPDX-License-Identifier: GPL-3.0-or-later Author: Oleg K Dzhimiev <oleg@elphel.com> ''' ''' Usage: ~$ blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN or ~$ <path-to-blender>/blender -b -P blender_generate_image_and_depth.py -- file1,file2,..,fileN - file names must include path - must be .obj format - at the same path all accompanying files must be present - .mtl and textures - no space after commas Notes: - *.obj format - include path in the *.obj name - 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 - ~$ which blender - alternatively can call from blender path 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: Loading @@ -32,21 +36,28 @@ Comment: - didn't work for some models in Blender v2.82.7 ''' import numpy as np import os import sys 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" # end constants scene = bpy.context.scene world = scene.world camera = scene.camera scene.render.resolution_x = 2592 scene.render.resolution_y = 1902 # fixed resolution for now scene.render.resolution_x = img_w scene.render.resolution_y = img_h scene.render.resolution_percentage = 100 world.use_nodes = False Loading @@ -58,10 +69,10 @@ objs.remove(objs["Light"], do_unlink=True) camera.location = (0,0,0) 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_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 Loading @@ -69,6 +80,7 @@ rn = scene.node_tree.nodes.new('CompositorNodeRLayers') depth = scene.node_tree.nodes.new('CompositorNodeOutputFile') depth.format.file_format = 'OPEN_EXR' depth.format.color_depth = '32' # TODO: try BW depth.format.color_mode = 'RGB' depth.format.exr_codec = 'ZIP' depth.base_path = model_output_folder Loading @@ -78,21 +90,12 @@ scene.node_tree.links.new(rn.outputs[2], depth.inputs[0]) 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))): os.mkdir(model_output_folder) for fpath in fpaths: obj_name = fpath.split('/')[-1][:-4] print(obj_name) bpy.ops.import_scene.obj(filepath=fpath, use_smooth_groups=False) Loading