AHH - YOU NOW TOLD THAT BOTTLES IN FIXED PLACES!
THIS IS AN INCREDIBLE PROBLEM.
All you have to do is look at each of the 12 spots and see if there is a black area there or not. Nothing could be simpler.
You do not need to perform detection of borders or shapes in ALL.
It is easy.
Then you pointed out that the box can be rotated, everything can be funny. The fact that the box can be rotated a little (or even a lot, from 0 to 360 each time) is very easy to handle. The fact that the bottles are in the “slots” (even if they are mixed) significantly changes the nature of the problem. The main problem (which is easy) is waiting for each new red square (box) to be centered under the camera. I just realized that you mean the "matrix" literally and specifically in the sentence in your original questions. This completely changes everything, compared to finding a messy mess of circles. Finding whether a blob is "on" in one of 12 items is a completely different problem for "identifying circles in the image." Perhaps you can send an image to close the question.
Finally, I believe that Kenny defined the best solution below : blob analysis.
"Count the number of bottles in the bottle case" ...
Are individual bottles separated in “slots”? those. 4x3 = 12 holes, one for each bottle.
In other words, you “only” need to determine if there is a bottle or not in each of the 12 holes.
Is it correct?
If so, your problem is incredibly simpler than the more general bottle heap problem anywhere.
Pretty simple, where do we see the bottles? Top, side, bottom, or? Do we always see tops / bottoms, or do they mix (i.e. are packed from top to bottom). These problems create huge differences.
Fatie source share