1

Using the code I found at How do I track motion using OpenCV in Python? and http://appdelegateinc.com/blog/2010/08/02/motion-tracking-with-a-webcam/; 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.

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.

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.

Community
  • 1
  • 1
cb22
  • 43
  • 1
  • 4

1 Answers1

0

No, I don't think OpenCV provides this facility. You are already doing it right by calculating the the gradient. How ever, you could do with a simple calculation of (x1, y1) and (x2, y2) to tell a gradient between two points. Using gnuplot may be heavy. You could also use Numdifftools.

Adding additional links on OpenCV that I did not find in previous answer.

pyfunc
  • 65,343
  • 15
  • 148
  • 136