# Bounding box fusion with constraints

I have N bounding boxes that I want to fuse/merge given some constraints. Each bounding box has a label.

Goal: The main goal is to minimize N.

Constraints:

1. Bounding boxes with the same label can be grouped together

2. A new bounding box resulting from a fusion can't overlap a bounding box with a different label:

How can this be solved ? Is it related to a classic OR problem ?