Dense Inverse Search (DIS) Optical Flow outputs incorrect flow(?)

Hello!

I am trying to port a python script to java but I am having some issues when creating a flow using the DIS Optical Flow .calc() method. Despite my inputs in java and python being the exact same I, for some reason, get two different flows. I am trying to understand why that is, and which flow is the correct one.

The python script uses OpenCV v. 3.4.* though I did try to bump it to the latest however that didn’t seem to change anything.
In my Java code I use v. 4.9.0-0. I tried to downgrade it but there seems to be no java bindings for that old version.

I wonder if I am missing something or if there could be a bug somewhere in the java implementation.

Hope someone can help :slight_smile:

Cheers!

hmm, if you could add example code (MRE) & 2 images ?

ppl here could try to reproduce your findings, ty :wink:

Yes, good point :sweat_smile:
So to keep it short, I have the following two images (which should be tiff files but I can’t upload that so you’ll get them as png instead):
scaled_data1

These images are fed into the DISOpticalFlow calc() method.
For python:

flow = cv2.DISOpticalFlow.create().calc(scaled_data1, scaled_data2, None)

And for java:

Mat flow = new Mat(scaledData1.size(), CV_32FC2);
DISOpticalFlow denseInverseSearch = DISOpticalFlow.create();
denseInverseSearch.calc(scaled_data1, scaled_data2, flow);

Now, when I compare the values from the python flow with the java flow, I find that these are not the same.

As a new user I can only post one image per post, so heres the second image :stuck_out_tongue: :

scaled_data2

1 Like

2 times scaled_data1 there ?

Ah, thats just a typo in this example… :grimacing:

… would have been far too easy :slight_smile:

we probably need to learn about those, too

Alright, one sec :+1:

These flow outputs are pretty large, how would you prefer to get them?
Just a snippet or should I zip and upload somewhere? :sweat_smile:

@berak I have tried to upload them here:

Available for 7 days.

the difference being that in the python version, the api knows to create its own flow result (perhaps with initialization), while in the java version, you create an uninitialized mat, which the flow calculation may use to iterate upon… and this may contain garbage data from the previous values in that part of memory.

just guessing here.

try it. create zeroed matrices in both cases, run the codes.

1 Like

I tried this as well and it seems to do nothing either :confused:
Could it be some default parameters that are different in the python implementation vs java?

EDIT: I tried to print the parameters available through the get-methods and they seem to be the exact same. The only one I couldn’t find in java was getVariationalRefinementEpsilon(). Not sure if that has any say in any of this :man_shrugging:

Sad bump.

Still need help to figure this out. I have tried to tweak some of the parameters of DISOpticalFlow despite them being the same as in python. However by tweaking them (primarily VariationalRefinementIterations) I could achieve a more reliable result.

But tweaking the parameters seems kind of random to me and as long as I get a different result from python I am not really satisfied. I would really like to achieve the same result or at least be able to understand why I can’t.