Hack Forums
[C#] Little Example of Motion Detection with Computer Vision - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] Little Example of Motion Detection with Computer Vision (/showthread.php?tid=5338403)



Little Example of Motion Detection with Computer Vision - SIM-1725686 - Jul 14, 2016

Hey guys, just found out about the EmguCV library (port of OpenCV to C#), and have been playing around with it.

The release of Pokemon Go has me really interested in augmented reality all of a sudden. I was thinking it would be cool if eventually games like those could include motion sensors...

Anyways, a first step towards something like this, I whipped a small app that you control by moving a bowl (or something circular). The procedure is straightforward:

1. Use computer vision to detect a circle.
2. Calculate its location, x and y, based on center and radius
3. Calculate ratio of each as compared to image's width and height, respectively
4. Calculate ratio of image size to window size
5. Multiply x and y by the ratio of the first ratio to the second ratio (three ratios total)
6. Move a cursor to the calculated position
7. #PROFIT





Here's a short video of it in action. You'll notice that when I hover over the button in the application, its text changes from "INACTIVE" to "ACTIVE." In addition, it is easily possible to outline the detected circle, in any color (I chose pink) in the preview window at the bottom of the form.

Also, here is the source code. Hopefully somebody can benefit from reading it.