Blog Post

How to track Stronghold high goalpost using vision system on your FRC robot.

7689

How to track Stronghold high goalpost using vision system on your FRC robot.

This past weekend was snow storm Jonas so I decide to do little write up for all the FRC teams on how to track Stronghold high goal using OpenCV on Raspberry pi.

Track the goal before you shoot so you can score highest.

At the core, Stronghold goal is just a visual pattern. A semi-circular window with bricks around. There are reflective tape markers but we will not be using them in this tutorial. All human player needs to do is scan for the pattern, our brain is able to pick out this pattern, even among all the distraction.

The question is, can computers do better? Can we create a program that can automatically find goal post? In fact, we can. Using computer vision techniques, we can find the exact location of goal post seen by the robot , much faster than any of human player could!

So we will build a Python script using OpenCV that can find reference goal image captured by the robot on the field.

What Do I need ?

All you need is Raspberry Pi, with Camera enabled. Python, NumPy, imutils and OpenCV installed on SD card. A little knowledge of basic image processing concepts would help, but is definitely not a requirement. This how-to guide is meant to be hands-on and shows you how to apply template matching using OpenCV. Don’t have these libraries installed? No problem. You can download a pre-configured SD card image from here. This has all the necessary computer vision, image processing, and machine learning packages pre-installed.

Our Objective

So our overall objective is to make reference image of the goal post and find the occurrence of this image in the captured frame. This will return us the position of the goal post in frame and by knowing this, we can shoot the ball accurately. As you’ll see later in this post, we’ll be able to accomplish this in only two lines of Python code. The rest of the code simply handles logic crosshair placement and camera image capture. We require two images to build our Python script to perform template matching.

Search Image of goalpost

for this post I am just going to use the image from official FIRST images like below. It is the cropped image from one of the Stronghold pictures.

GoalPost

This is the image piece we will search in any frame to locate the high goalpost. If you are doing this on-field you should use the Pi camera to capture the image on the field so accuracy is better.

Frame images of field.

The second image is our frame image for locating the goal post in I have used few of below images to test.

frame image 1

frame image 2

frame image 3

Python Code



Python program to do the processing have few components import the required parts and provide the arguments in testing mode. If you are using this on the field then you should uncomment appropriate part to grab the frame from Raspberry Pi camera.

python program

Next part mainly grabs the frame and scales it to 640 pixels so processing is faster. do this if you want to improve performance.

python program

Now all we need to do next is use OpenCv matchTemplate method to search for our goal in the frame.

python program

Calculations of the center in the code will find the center of the target and draw crosshair so it is visible. On the field, you do not need to do this but for debugging you will need this.  You can transfer these coordinate to RoboRio on serial line or I2C line. I am not including that part here, maybe some-other time.


Results

track Stronghold high goalpost

track Stronghold high goalpost

track Stronghold high goalpost

Comments (0)

No comments at this moment
Please Login to add your comments

Featured Posts

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more

The mindsensors Grove Sensor Adapter makes it easy to use a variety of unique Grove sensors with the...

Read more

Poll

  • What do you use to program your FRC Robot?
    Total: