What I wanted to do with my final project was to solve the problem of goal line detection. In sports such as Hockey or Soccer, what counts as a “goal” is when the ball or puck makes it all the way inside of the goal, e.g. across the goal line. Now, there is a big issue right now with the goal being made but not counted, because after the ball or puck crosses the line, the goal keeper knocks it back out.
I tried several iterations with this, but eventually settled on using OpenCV with a webcam as my solution to this problem. The nice part about this, is that the webcam is cheap, and it is an easy matter to adjust the code to look for the specific ball/puck that we are trying to detect. Essentially, you set up the webcam underneath the goal line, and watch for when the ball crosses that line. Here are some photos of the set up the I used during my demo to demonstrate the setup.
You can see that the there is a piece of plexi-glass on top of which the goal is sitting. It is through this that the webcam looks. Now, this set up will work great with hockey, all you need to do is put very high quality ice under the goal, and because the code looks for a part of the ball/puck, even if the ice gets scratched up, the camera will still be able to pick up on it. The issue comes in with sports such as soccer, because it is difficult to make a grass field clear.
Here’s a screen shot of the code that I used for my project.
With this, I wrote it all up in Python, using OpenCV for the image detection. This was actually the easiest way of doing the image recognition, and while it took me about 5-6 hours to acquaint myself with the library, once I had learned it, it was a simple matter to start looking for the ball. The resource that I used to learn OpenCV is at this link: http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_tutorials.html
The only hardware that is needed to make this work is a simple webcam. The one that I got was $20 at BestBuy. This is a pretty inexpensive implementation, and would be very easy to set up for pee-wee sports leagues, and school teams. The rest of the set up, with the plexi-glass and 2X4s was simply for the demo, and is not necessary to get everything going on goal detection.
In the end, I managed to get everything working with the camera. Here are a few screenshots from my computer that show it working:
You can see in these photos that when the ball is on the left of the line in the center of the screen, nothing displays, however, once that ball crosses that line, the screen pops up and says “GOAL!” So, all that you have to do is line up the center of the camera’s view with the goal line, and you’re good to go.
In the future, I would like to implement some code that will track the ball’s path, and determine if the ball crossed the line, even if it obstructed by the goal keeper once it crosses that line. I would also like to implement a more hardware based method of detection as well that will provide a second source of confirmation, in case the camera fails. This method will likely involve using an RF field to detect the goal.
Thanks for reading through!