Search code examples
opencvemgucvmotion-detection

Determine movement/motion (in pixels) between two frames


First of all I'm a total newbie in image processing, so please don't be too harsh on me. That being said, I'm developing an application to analyse changes in blood flow in extremities using thermal images obtained by a camera. The user is able to define a region of interest by placing a shape (circle,rectangle,etc.) on the current image. The user should then be able to see how the average temperature changes from frame to frame inside the specified ROI.

The problem is that some of the images are not steady, due to (small) movement by the test subject. My question is how can I determine the movement between the frames, so that I can relocate the ROI accordingly?

I'm using the Emgu OpenCV .Net wrapper for image processing. What I've tried so far is calculating the center of gravity using GetMoments() on the biggest contour found and calculating the direction vector between this and the previous center of gravity. The ROI is then translated using this vector but the results are not that promising yet.

Is this the right way to do it or am I totally barking up the wrong tree?

------Edit------

Here are two sample images showing slight movement downwards to the right:

http://postimg.org/image/wznf2r27n/

Comparison between the contours:

http://postimg.org/image/4ldez2di1/

As you can see the shape of the contour is pretty much the same, although there are some small differences near the toes.


Solution

  • Seems like I was finally able to find a solution for my problem using optical flow based on the Lukas-Kanade method.

    Just in case anyone else is wondering how to implement it in Emgu/C#, here's the link to a Emgu examples project, where they use Lukas-Kanade and Farneback's algorithms: http://sourceforge.net/projects/emguexample/files/Image/BuildBackgroundImage.zip/download

    You may need to adapt a few things, e.g. the parameters for the corner detection (the frame.GoodFeaturesToTrack(..) method) , but it's definetly something to start with.

    Thanks for all the ideas!