### Counting tablets

I have developed a pill counter. It uses something similar to this tutorial and to [this other tutorial].(https://www.pyimagesearch.com/2015/11/02/watershed-opencv/)

However (as the next step) I want to count also tablets such as:

Although the segmentation process is a bit complicated (because of the semi-transparency of the tablets) I have managed to get this

My problem is here. How can I count the elongated tablets, separating each one from the image, similar to the final results in the linked tutorials?
I would appreciate if someone can help me to find a solution.
So far I have applied distance transform, then smooth it with a Gaussian filter and then watershed and I got

As you can see, it does not work well, specially for adjacent tablets.

The solution does have to work for this image and also for other arrangements of the tablets, the most difficult being for example

Thank you very much for any pointer or help on how to solve this problem. (My project has to address more complicated problems too, but would like to start with this)