Maystro
Maystro

Reputation: 2955

Compute global motion opencv 2.4.x C++

Here are two images, one captured before an action has been made by the surgeon and the other afterwards.

Before: enter image description here

After: enter image description here

Difference: (After - Before) + 128. (The addition of 128 is just to have a better image) enter image description here

As pointed to by the white arrows, there has been a global motion affecting all the objects.

So, I need to estimate it in order to get more valuable information on what's happening in the scene.

I already knew that OpenCV 3.0 helps in this context where it's implemented some methods that estimate the dominant motion between two images or two list of points. But I'm using so far OpenCV 2.4.x because I have dependencies with libraries already installed on my machine so I'm looking for alternative solutions or any other code that does what I want.

Upvotes: 4

Views: 1347

Answers (1)

PhilLab
PhilLab

Reputation: 5027

You are looking for a dense optical flow algorithm:

The result for

cv::calcOpticalFlowFarneback(img1, img2, flowField, 0.5, 3, 10, 5, 5, 1.1)

is the following flow field where you clearly see the changes: enter image description here

As for the global motion detection:

  • If the global motion is very small (as in your example) you can just threshold the motion vectors: throw small values away.
  • If it is larger, find the dominant motion vector and subtract it from all of your vectors. Then threshold to throw small values away

Upvotes: 2

Related Questions