I want to find the average of the optical flow, I could extract the features from the first frame and found their location in the next frame. Now, I want to find the average of the displacement in order to translate the image back to its stationary background in order to stabilize the image.
// here I take the optical flow
cvCalcOpticalFlowPyrLK(frame1_1C, frame2_1C, pyramid1, pyramid2, frame1_features,
frame2_features, corner_count, optical_flow_window, 5,
optical_flow_found_feature, NULL,
optical_flow_termination_criteria, NULL);
// here the features that I extract them
for( int i=0; i < corner_count; i++ ) {
CvPoint p,q;
if ( optical_flow_found_feature[i] == 0 ) continue;
p.x = (int) frame1_features[i].x;
p.y = (int) frame1_features[i].y;
q.x = (int) frame2_features[i].x;
q.y = (int) frame2_features[i].y;
double angle = atan2( (double) p.y - q.y, (double) p.x - q.x );
double hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) );
Now I want to take the average for them, and if you want me to show you more of the code I'm ready to do that.
The corner_count is the number of the features.
See Question&Answers more detail:os