Skip to content

ADC crashes when saving empty crop #154

Description

@rhine3

Sometimes a detection's bbox boundaries are so small that they round to a set of bbox boundaries with zero area (e.g., [400, 0, 500, 0]). When this happens, ADC crashes with the response ValueError: cannot write empty image as JPEG. This line is included in the traceback:

detection.save_cropped_image_data(
source_image=image,
base_path=user_data_path,
)

If we just validate that bbox_area is a positive value before trying to save it, we could skip saving when the bbox is empty. I replaced those lines above with this temporary patch on my own machine:

                if area_pixels is not None and area_pixels > 0:
                    detection.save_cropped_image_data(
                        source_image=image,
                        base_path=user_data_path,
                    )
                else:
                    logger.warning(
                        f"Detected object with bbox {detection.bbox} has area 0, skipping cropped image save."
                    )

However, I don't know how this will affect downstream operations like trying to display an expected cropped image that is not there.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions