I'm trying to do something like this:
<http://www.youtube.com/watch?feature=player_embedded&v=MIYt1yNwoZU>

and I'm on the right way, it works well for 2 hours coding. But I have some question:

* I'm using opencv 2.4 and there are some options around.. see [here](http://opencv.itseez.com/modules/video/doc/video.html). which one is the best? lucas kanade with some automatic feature detection? or maybe a simple global orientation is enough? or even kalman filter? for now I'm using a dense farneback’s algorithm and i think is the first (= more simple) option but maybe is not the best one.
* after calculating optical flow on the image (scaled down by factor of 2 for calculating optical flow because it is an hard work) I take the average of the vectors. normal average, summing all of them and dividing from the number of vectors. so with a nested for loop on flow mat. better way?

```
Point2f average_motion(0,0); float n=1;

for(int y = 0; y < flow.rows; y += step)
    for(int x = 0; x < flow.cols; x += step) {

        const Point2f& fxy = flow.at<Point2f>(y, x);

        if( abs(fxy.x) > threshold || abs(fxy.y) > threshold) {
            average_motion += fxy;
            n++;
        }

    }
 average_motion *= 1/n;

 average_motion *= 1/n;
 cout << average_motion << endl;

```
* I'm moving the rects BUT the right/left movement seems to be a little bit weird, instead the up/down works really nice! someone can explain me why?
* translating is ok, but i'm stuck on rotating.. if i get the average vector how can i get the degree? I've tried with angle between vectors with X axis but is does not work nice. some hint?
* Now I'm drawing stuff with opencv drawing api but from 2.4 there is also opengl support.. and should be nice, but i don't find example on that..