title: Getting the general direction of motion using OpenCV and Python
body: <p>Using the code I found at <a href="https://stackoverflow.com/questions/3374828/how-do-i-track-motion-using-opencv-in-python">How do I track motion using OpenCV in Python?</a> and <a href="http://appdelegateinc.com/blog/2010/08/02/motion-tracking-with-a-webcam/" rel="nofollow noreferrer">http://appdelegateinc.com/blog/2010/08/02/motion-tracking-with-a-webcam/</a>; I can track motion quite well using Python and OpenCV. I modified it slightly so instead of drawing circles on the image, it will print out the (x,y) co-ords of what it detects. Now, this works great for showing the "exact" location of the motion, but I would like to find out the general direction, for example, is it going up or down.</p>
  
  <p>I have an idea, namely once I have a few points, use gnuplot to plot all the y-coords VS number, then calculate a line of best fit. If the gradient is positive then the motion is up, and if it is negative, the motion is down.</p>
  
  <p>While I'm fairly certain this would work, it seems rather "hacky". I'm wondering if there is a better way of doing this, since I'm quite new to OepnCV.</p>