1 | initial version |
There are a lot of different ways to attack this problem (as you've found out!). As gfx suggested, you could look at the hierarchies, which give you some extra information about the contours. Running some type of feature descriptor might also help (I imagine that dark shaded area will have less features in them than the actual fish).
I don't see any Regions of Interest filtering going on there -- where you only look for the target near where the last one was. It really cuts down on false positives and processing time. If it's not found, then you can iteratively lower thresholds and expand the ROI until you find the object.
If you want to look at some more pre-baked solutions, CamShift and Meanshift might provide all you need, as well as running a feature description and then applying homography.
I've had good luck with the MILTracker in the OpenCV contrib repository. They have a tracker interface there are quite a few different algorithms. If you compile OpenCV with that added in, you have a nice consistent API where you can pretty simply plug and play various trackers as well as write your own that conform.....that's only if you need to get pretty fancy though.