liuyuan-pal / SyncDreamer

[ICLR 2024 Spotlight] SyncDreamer: Generating Multiview-consistent Images from a Single-view Image
https://liuyuan-pal.github.io/SyncDreamer/
MIT License
906 stars 39 forks source link

Depth map rendering code in the provided dataset from one drive? #50

Closed HansenHuang0823 closed 1 year ago

HansenHuang0823 commented 1 year ago

It's such a nice work! Could you please provide the code for rendering the depth image "xxx-depth.png" in the dataset? I'd like to use it.

liuyuan-pal commented 1 year ago

I added the following codes to the original script.

def prepare_depth_outputs():
    tree = bpy.context.scene.node_tree
    links = tree.links
    render_node = tree.nodes['Render Layers']
    depth_out_node = tree.nodes.new(type="CompositorNodeOutputFile")
    depth_map_node = tree.nodes.new(type="CompositorNodeMapRange")
    depth_out_node.base_path = ''
    depth_out_node.format.file_format = 'OPEN_EXR'
    depth_out_node.format.color_depth = '32'

    # the object is inside the unit cube (length=1,center=0)
    # the camera is located on an unit sphere with radius of 1.5 and looking at the origin
    # so the max depth is 1.5+sqrt(3)/2 = 2.3660
    # so the min depth is 1.5-sqrt(3)/2 = 0.6339
    # valid depth value would be [0.63,2.37]
    # if the depth value in [0.6,0.63] [2.37,2.4], then the depth value is invalid.

    depth_map_node.inputs[1].default_value = 0.6
    depth_map_node.inputs[2].default_value = 2.4
    depth_map_node.inputs[3].default_value = 0
    depth_map_node.inputs[4].default_value = 1
    depth_map_node.use_clamp = True
    links.new(render_node.outputs[2],depth_map_node.inputs[0])
    links.new(depth_map_node.outputs[0], depth_out_node.inputs[0])
    return depth_out_node

if 'View Layer' in bpy.context.scene.view_layers:
    bpy.context.scene.view_layers['View Layer'].use_pass_z = True
    bpy.context.scene.view_layers['View Layer'].use_pass_object_index = True
else:
    bpy.context.scene.view_layers['ViewLayer'].use_pass_z = True
    bpy.context.scene.view_layers['ViewLayer'].use_pass_object_index = True
bpy.context.scene.use_nodes = True
depth_out_node = prepare_depth_outputs()

depth_out_node.file_slots[0].path = os.path.join(args.output_dir, object_uid, f"{i:03d}") + '-depth'
HansenHuang0823 commented 1 year ago

Thank you very much for your fast reply and patience!!!