Bottle detection is done but the caps counting of all bottle each row not going with good results

I have successfully detected Coke, Fanta, and Sprite beverage bottles placed in the refrigerator, but it is not going to count all the bottles placed in the same row by detecting their caps. The attached picture is a reference to see the test sample. How can I count all the bottles in the same row from front to back by detecting the git’s caps?

crosspost:

https://stackoverflow.com/staging-ground/79333521

no such thing here . . . . .

over there, this was provided: https://i.sstatic.net/fzDMSxw6.png