DLR-RM / BlenderProc

A procedural Blender pipeline for photorealistic training image generation
GNU General Public License v3.0
2.79k stars 449 forks source link

AttributeError: 'Curve' object has no attribute 'get_bound_box' when calling compute_poi #1113

Open schirrmacher opened 4 months ago

schirrmacher commented 4 months ago

Describe the issue

I copied some code and was facing an issue with:

objs = bproc.loader.load_blend(
    args.scene,
    obj_types=[
        "mesh",
        "curve",
        "curves",
        "hair",
        "armature",
        "empty",
        "light",
        "camera",
    ],
    data_blocks=[
        "armatures",
        "cameras",
        "curves",
        "hair_curves",
        "images",
        "lights",
        "materials",
        "meshes",
        "objects",
        "textures",
    ],
)

poi = bproc.object.compute_poi(objs)
Error: Python: Traceback (most recent call last):
  File "/Users/mav/dev/BlenderProc/examples/basics/semantic_segmentation/main.py", line 66, in <module>
    poi = bproc.object.compute_poi(objs)
  File "/Users/mav/dev/BlenderProc/blenderproc/python/types/MeshObjectUtility.py", line 701, in compute_poi
    bb_points = obj.get_bound_box()
AttributeError: 'Curve' object has no attribute 'get_bound_box'

I can create a PR if you like, the question is why do some object types not have this function. I simply fixed it with:

    for obj in objects:
        if hasattr(obj, "get_bound_box") and callable(getattr(obj, "get_bound_box")):
            # Get bounding box corners
            bb_points = obj.get_bound_box()
            # Compute mean coords of bounding box
            mean_bb_points.append(np.mean(bb_points, axis=0))

in def compute_poi(objects: List[MeshObject]) -> np.ndarray.

Minimal code example

No response

Files required to run the code

No response

Expected behavior

I would have expected no AttributeError

BlenderProc version

2.7.1

cornerfarmer commented 4 months ago

Hey @schirrmacher,

thanks for the report. I think the problem is that load_blend returns a List[Entity] while compute_poi requires a List[MeshObject] (Entity is a parent class of MeshObject). So you would need to filter out all objects that are no MeshObject first.

If you want the curves to be considered in the poi computation, you probably would need to write your own compute_poi function.