4

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.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
Maystro
  • 2,907
  • 8
  • 36
  • 71
  • I'll share a link [here](http://study.marearts.com/search/label/Trash%20dumping%20detection). It pertains to a video, not a before/after image pair, but perhaps it could give you an idea. I would suggest skimming through the other posts on that blog, there may be something useful for you. – Trés DuBiel Jan 24 '16 at 23:11

1 Answers1

2

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
PhilLab
  • 4,777
  • 1
  • 25
  • 77
  • how did you get exactly this image? – Maystro Jan 27 '16 at 17:52
  • Perhaps using this - https://github.com/Itseez/opencv/blob/master/samples/cpp/fback.cpp – Prabindh Jan 28 '16 at 04:39
  • Yes. I think I swapped the image order but using the images posted above this is the result. The configuration was ``cv::calcOpticalFlowFarneback(previousImage, image, flowField, 0.5, 3, 10, 5, 5, 1.1)`` – PhilLab Jan 28 '16 at 08:33
  • but I'm not really able to understand how could you get this image? [here](http://stackoverflow.com/questions/34750415/optical-flow-ignore-sparse-motions/34892970#34892970) is what I'm getting – Maystro Jan 28 '16 at 14:54
  • the link shows a sparse optical flow approach (e.g. the flow of several keypoints). The Farneback Optical Flow works directly on the image and thus returns a flow vector for each pixel – PhilLab Jan 28 '16 at 14:58
  • I know.. I just meant take a look over the question and not the answer so you get what I mean by not being able to reproduce the same figure you got. – Maystro Jan 28 '16 at 15:35