Tracking multiple deformable objects using OpenCV

asked 2016-06-17 04:59:48 -0500

Hello Community,

I am new in OpenCV and in tracking topic. I have a lot of experience in computer vision, but in the area of industrial applications. My current task is more a research topic from the neuroscience. The task is to track mice in the cage. The mice are active during the night, so we use IR lightning and we get gray-scaled images.There are normally from 2-5 animals in the cage at the same time. There are several problems in mice tracking:

    • The animals have any remarkable texture.
  • The animals are very similar to eachother.
  • Mice are very deformable.
  • Mice move unpredictable and can suddenly change their moving directions.

  • The animals are often occluded, because they interact with eachother, or desappear from the scene, because they are hidden by other animals in the cage.

I have following questions:

  • Which algorithm is most suetable for such a tracking task?
  • I have only one model definded and want to track all presented obejcts in the video. Is ist possible?

I would very appreciate your help and thank you in advance!

Best regards,


edit retag flag offensive close merge delete


In my opinion, motion detection techniques like background subtraction combined with Kalman filter + Hungarian algorithm to assign the same id for each object could be a part of the final solution.

Eduardo gravatar imageEduardo ( 2016-06-17 07:30:24 -0500 )edit

Hi Eduardo, thank you for quick response. I woukld like to ask you again, if I correctly understood your answer. With the background segmentation I will determine the regions of interest and then apply the kalman filter and hungarian algorithm? Is the combination KF+HA a part of 3rd party tracking library or I should integrate the code into my project?

Daschkin gravatar imageDaschkin ( 2016-06-17 08:53:06 -0500 )edit

In fact I have no experience on this subject.

If the camera is static and the mice always move or you are only interested with active mice, a background subtraction method should be efficient and relatively cheap in term of computation time. You can perform some morphology operations to clean the result and after cluster the objects with for example the DBSCAN algorithm.

Otherwise, you will have to find a method to first detect the mice and then track them (with the OpenCV tracking API, optical flow, etc.). The KF and the HA are complementary tools in my opinion. The Kalman filter allows to predict and smooth the tracking whereas the Hungarian algorithm allows to assign the same id to the same object.

Eduardo gravatar imageEduardo ( 2016-06-17 11:04:50 -0500 )edit

It's probably better to use connectedComponents rather than DBSCAN. You can use cv::moments to get centroids, and HUMoments can work as a descriptor.

You use the Kalman Filter to filter the centroid locations. The part you need to write matches your existing track with a Kalman Filter to the detections in the new frame.

Tetragramm gravatar imageTetragramm ( 2016-06-20 18:04:11 -0500 )edit