Sipeed MaiX Bit OpenMV Demos - Computer Vision
This is the second article in series about Sipeed AI on the Edge microcontroller platform. This time I will be writing about MaiX Bit(link to Seeed Studio Shop), a smaller, breadboard ready development board. It's specifications are very similar to MaiX Dock, the board I used for last tutorial, since they use the same chip, Kendryte K210.
We're going to be using micropython firmware to try some OpenMV demos. Here's description from OpenMV homepage:
The OpenMV project is about creating low-cost, extensible, Python powered, machine vision modules and aims at becoming the “Arduino of Machine Vision“.
Python makes working with machine visions algorithms much easier. For example, the find_blobs() method in the code finds color blobs and returns a list of 8-valued objects representing each color blob found. In Python iterating through the list of objects returned by find_blobs() and drawing a rectangle around each color blob is easily done in just two lines of code.
So, despite MaiX Bit features dedicated neural network accelerator, sometimes it might be easier to just use OpenMV hard-coded algorithms to do the job or use them alongside each other.
Some use cases that come to my mind are:
Line detection for line follower bot
Detecting traffic lights with circle and color detection
Using face detection to find the faces for face recognition(with DNN)
GitHub repository for this article
Step 1: Flash Micropython Firmware
First of all we will need to flash micropython firmware to our board. A precompiled binary is included in github repository for this article, together with kflash.py( a flash utility). If you wish to compile the firmware from the source code, just download the source code from https://github.com/sipeed/MaixPy, install the toolchain and compile the source code into maixpy.bin file. Detailed build instructions can be found here.
Flash the binary file with
sudo python3 kflash.py maixpy.bin
After successful flashing follow to the next step.
Step 2: Connect to MaiX Bit
Now our MaiX Bit should be accessible through a USB serial connection with baudrate 115200. You can use your favorite software for serial communication or just cat and echo commands, whatever suits your needs. I was using screen for serial communication and find it very convenient.
The command for establishing a serial communication session with screen is
sudo screen /dev/ttyUSB0 115200
where /dev/ttyUSB0 is the address of your device.
You might need to press reset button on your microcontroller to see the greeting message and python interpreter prompt.
Step 3: Run the Demos!
Now you can access copy mode by pressing Ctrl+E and copy-paste the demo codes. To run them press Ctrl+D in copy mode.
If you don't want to record the videos, you need to comment the video recording lines. Otherwise the code will throw an exception if there's no SD card inserted.
Here are short descriptions of each demo:
Find circles - uses find_circles function from OpenMV. Needs more tweaking for your specific application, particularly threshold(controls what circles are detected from the hough transform. Only
circles with a magnitude greater than or equal to threshold are returned) and r_min, r_max values.
Find rectangles - uses find_rects function from OpenMV. You can play around with threshold value, but the value I have in demo works quite good for finding rectangles.
Find faces, find eyes - uses find_features function with Haar Cascades for detecting eyes and frontal face in the image. You can play around with threshold and scale values for the right speed-accuracy trade-off.
Find infinite lines - uses find_lines function to find all infinite lines in the image using the hough transform.
Detect color - uses get_statistics function to obtain percentile object and then converts mean values of LAB tuple to RGB values tuple. I wrote this example myself and it works quite well, but do keep in mind the results of color detection will be affected by ambient light conditions.
You can find many more interesting demos in OpenMV github repository! They are mostly compatible with MaiX Bit micropython, the only thing you need to remember is to add sensor.run(1) after setting the pixformat and framesize.
Happy experimentation with OpenMV code. If you have any questions or want to share some of your interesting results, don't hesitate to reach me on Youtube or LinkedIn(link in YouTube video). Now, excuse me, I'll go make some robots!