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.
Yes, good point
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
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.
I tried this as well and it seems to do nothing either
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
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.