# Farneback’s opticalflow implementation bug?

I'm following papers regarding the Gunnar Farneback’s opticalflow algorithm and its OpenCV implementation. Meanwhile, I found a suspicious calculation in the code.

The calculation is at line 288-289 in https://github.com/Itseez/opencv/blob..., and the code is here:

```
r2 += r4*dy + r6*dx;
r3 += r6*dy + r5*dx;
```

Reading the surrounding lines, the above code is seemed to be the calculation of the 2nd term of the formula (7.33), A(x)d(x), in [Farneback2002].

However, if my understanding is correct, the calculation should be the following:

```
r2 += r4*dx + r6*dy;
r3 += r6*dx + r5*dy;
```

Is my understanding wrong?

[Farneback2002] Gunnar Farneback, Polynomial Expansion for Orientation and Motion Estimation.

If you have a test ready (I think Middlebury tests are available) then you could run it both ways and see which generates results closer to ground truth. Not perfect and not the same as understanding, but perhaps worthwhile.

I'd like to know if this implementation is intended or not. Nevertheless the test generates closer results, if the implementation has an unintended code then it is a bug. If it is intended, I want to know its intention.