OpenCV
With OpenCV on NavQ, you will be able to harness a vast library of computer vision tools for use in HoverGames. OpenCV is installed out of the box on the HoverGames-BSP image and can be installed easily through the package manager on the HoverGames-Demo image. If you'd like to get a jump start on OpenCV, follow the guide below to create a program that detects red objects.
Quick Example
Let's go through a quick example of running OpenCV on the NavQ to identify a red object in an image taken on the Google Coral camera. This example will be written in Python and uses OpenCV.
Installing OpenCV
If you are using the default OS that is shipped with the NavQ, you can skip this step.
If you're using the HoverGames-Demo image, you'll need to install python3-opencv. To do so, run the following command in your terminal:
Imports
First, create a new python source file (name it whatever you want!). We only need two imports for this program: opencv (cv2) and numpy. Numpy is used to create arrays of HSV values.
Capturing an image
To capture an image, we must first open a camera object and then read from it.
Downsizing the image
To make our OpenCV pipeline run faster, we're going to shrink our image down to 640x480 resolution. This resolution isn't so small that the image quality will be reduced enough to make a difference in detecting objects, but it will make OpenCV process our image much quicker.
Another pre-processing step that we will run is a box blur. This will get rid of small artifacts in the image that can throw off our pipeline and will make detecting large objects much easier.
Color filtering
In order to find objects that are red in our image, we will apply an HSV filter to the image to create a mask of the color red in the image.
The lower_red
and upper_red
variables are found by using a program called GRIP. GRIP is a GUI program for OpenCV. It has tons of great features including code generation. To check GRIP out, go to the website here.
Finding contours
To find the location of the objects in our image, we will find contours in the mask and sort them by total area. This will allow us to filter out smaller objects that we aren't interested in. We will also be able to detect the objects' position in the image and draw a box around them.
Storing the generated images
Finally, we will store the images we generated from this program: the mask and the final image with annotations (bounding box and text).
Running the code
To run the code, you'll need to use python3. Run the following command (<file.py> will be the filename that you saved the code to):
Source code
Here is the complete source code if you'd like to run it on your own NavQ as an example:
Last updated