开发者

Getting the general direction of motion using OpenCV and Python

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 m开发者_运维问答otion 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.


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.

  • http://opencv.willowgarage.com/documentation/python/cookbook.html#using-goodfeaturestotrack
  • http://opencv.willowgarage.com/documentation/python/index.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜