Ask Your Question
0

Optical Flow Arrow Tips Pointing the Wrong Way

asked 2012-12-02 06:50:44 -0600

aliciadominica gravatar image

This is an extremely trivial question but it kind of bugs me. I modified the optical flow algorithm here to use the entire video and display it: http://robots.stanford.edu/cs223b05/notes/CS%20223-B%20T1%20stavens_opencv_optical_flow.pdf

I extract the optical flow correctly and it shows the arrows and everything but when the motion is from left to right the arrows are pointing to left rather than to right. Actually arrows are always pointing to left and it doesn't change. I tried changing the angle equation below, it doesn't change anything. I posted the original arrow calculation and drawing code below and I hope someone can help.

Thanks in advance

CvPoint p,q; /*  "p" is the point where the line begins.          
/*  "q" is the point where the line stops. 
/*  "CV_AA" means antialiased drawing. 
/*  "0" means no fractional bits in the center cooridinate or radius.     
*/
      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;   
      angle = atan2( (double) p.y - q.y, (double) p.x - q.x );
      double hypotenuse;  hypotenuse = sqrt( square(p.y - q.y) + square(p.x - q.x) )
      q.x = (int) (p.x - 3 * hypotenuse * cos(angle));
      q.y = (int) (p.y - 3 * hypotenuse * sin(angle));
      cvLine( frame1, p, q, line_color, line_thickness, CV_AA, 0 );
      /* Now draw the tips of the arrow.  I do some scaling so that the
        * tips look proportional to the main line of the arrow.
        */   
      p.x = (int) (q.x + 9 * cos(angle + pi / 4));
      p.y = (int) (q.y + 9 * sin(angle + pi / 4));    
      cvLine( frame, p, q, line_color, line_thickness, CV_AA, 0 );
      p.x = (int) (q.x + 9 * cos(angle - pi / 4));
      p.y = (int) (q.y + 9 * sin(angle - pi / 4));    
      cvLine( frame, p, q, line_color, line_thickness, CV_AA, 0 );
    }
edit retag flag offensive close merge delete

Comments

the code seems right could u provide the video on which u applied optical flow

gpsinghsandhu gravatar imagegpsinghsandhu ( 2012-12-05 14:11:04 -0600 )edit

The video is called 861-13_70.mov in UCF Crowd Dataset

aliciadominica gravatar imagealiciadominica ( 2012-12-13 07:08:51 -0600 )edit

Isn't the mistake in your atan2 call ? If your vector is PQ, then you should have some Q-P almost everywhere.

Emmanuel gravatar imageEmmanuel ( 2012-12-28 14:47:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-01-03 08:28:38 -0600

theodore gravatar image

updated 2013-01-03 08:30:24 -0600

the code is ok, i was facing the same problem and the cause was that i was passing wrong images in to the calcOpticalFlowPyrLK() function. According to the documentation the images should be 8-bit (i.e. grayscale) both of them, so check if this is the problem or not. In my case i was passing rgb images, while the input points were from a binary.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-12-02 06:50:44 -0600

Seen: 2,564 times

Last updated: Jan 03 '13