Blender 粒子系统的边界框和分割掩码

问题描述 投票:0回答:0

我正在尝试用搅拌机中的粒子系统模拟多个下落物体。

为了训练某些 CNN,我需要场景中可见的单个元素的分割掩码。到目前为止,我只能执行部分导出掩码任务。比如通过组合节点导出掩码或者使用python提取一些属性。

到目前为止我尝试的是:

  • 通过粒子索引导出蒙版(见图片)。分割图像中物体的颜色随机变化。由于它们在某些时候会重叠,因此该解决方案并不适用。分割图像的边缘也比较模糊,主要是设置:Film -> Pixel Filter -> Width 属性(如果设置为0,渲染图像是 也受到影响)。

  • 我看到的另一种可能性是通过 python 导出掩码。因此,我创建了一个脚本(到目前为止)导出图像中粒子的中心点。然而,我可能会遍历可见粒子并一个一个地禁用并始终保存图像,但这将使用大量的内存和时间。

    import bpy
    from bpy_extras.object_utils import world_to_camera_view
    
    context = bpy.context
    dg = context.evaluated_depsgraph_get()
    ob = context.object.evaluated_get(dg)
    
    ps = ob.particle_systems.active
    
    scene = bpy.context.scene
    cam = bpy.data.objects['Camera']
    
    render = scene.render
    res_x = render.resolution_x
    res_y = render.resolution_y
    
    for frame in range(30,35):
        scene.frame_set(frame)
        bpy.ops.render.render(write_still = True)
        
        print("res_x:{},res_y:{}".format(res_x, res_y))
        for particle in ps.particles:
            if particle.is_visible:
                print(particle.location)
                coords_2d = world_to_camera_view(scene, cam, particle.location)
                x = coords_2d[0]
                y = coords_2d[1]
                dist_to_cam = coords_2d[2]
                rnd = lambda i: round(i)
                print("x:{},y:{}".format(rnd(res_x*x),res_y- rnd(res_y*y)))

如果有人能告诉我一种更可靠的清洁方法来导出所有可见单粒子对象的蒙版,同时考虑重叠,在搅拌机中我将非常感激。

谢谢

python blender bpy
© www.soinside.com 2019 - 2024. All rights reserved.