After reading the question and your comment on stackoverflow, it seems that you don’t need to count them but you want to measure them. So is it really necessary to measure ALL rice grains? Why don’t you just put all good grains into the dish and the bad you may throw away if you wish.
Seperation is a difficult thing if elements are overlapped. There’s a reason why all good captchas have overlapping elements. Your single grains seem to be found very well and overlapping grains can’t be accurately measured anyway.
As far as I see the single rice grains are all convex, the overlapping contours are not. Measure the convex contours and give all others some extra treatment