Detecting similar objects in close proximity

We are coding a Java based OpenCV image processing pipeline to identify locations and rotational angles of colored blocks. Using the typical techniques of color thresholding and edge detection we are quite successful with scenarios like that shown in Image “A”. Adding in some erosion also handles situations where similarly colored blocks are close to each other, up to a limit. We are looking for insights on how to detect individual blocks in scenarios like those shown in image B and C. In those scenarios, erosion is not sufficient to create separation between the blocks. Thanks in advance for any tips!

these yellow blocks do appear as a single contiguous area in the picture.

it could very well be one solid object having the same appearance.

you need something that brings some expectations to the task, such as the expectation that these objects are blocks, not shaped arbitrarily.

that’s AI. make AI “see” two blocks in that shape: object detection (bounding boxes) or instance segmentation (masks).

if there are clues in the picture, the model is very likely to use them. if not, it’ll give a plausible output that you can’t prove wrong without knowing the truth.

Thank you for those insights. We had reached a similar conclusion. Is there anything in OpenCV that might take advantage of the expectation that the blocks have a specific size? In our particular application, the distance from the camera remains fixed and we can use OpenCV to correct for lens distortion. We know that the blocks are rectangular and we can calibrate the expectation that the lengths should be within a certain range and join at approximately a right angle. We think this could be seen as a form of a polygon packing problem and are wondering if openCV has anything to address that?