Art is often made to appeal to a specific set of viewers. This is the 4th blog in a series exploring the idea of using AI to recognize a viewer and adapt art to their age or interest. The intent is to encourage early art appreciation while being attractive to all household members.
In this post the progress in getting image recognition to start and run more quickly is described along with a means to communicate from one Raspberry Pi to another when a face is recognized.
Speeding Things Up
In the second post the means of capturing training photos, processing them, and then using the encoded results to recognize faces and track them on a monitor was presented. It was noted that the update frequency was fairly slow and CPU intensive. Adding more photos to the training set to improve accuracy, and adding additional persons to be recognized slows things even further. The project goal is to add as many as eight different faces and have them recognized with reasonable accuracy and speed (reasonable to be defined at a later date :-).
The portion of the program that processes the training photos was removed and run separately. The recognition program then accesses the encoded data and thus starts faster. The portion of the program that tracks faces and draws boxes around them on the screen was removed as it is not needed. The speedup is noticeable but has not been quantified. But now that faces are no longer shown on the monitor and tracked it is necessary to indicate recognition another way.
Talking Pi to Pi
Originally the connection was to be serial or perhaps Bluetooth but there are numerous GPIO that are not being used on the two computers. Since there is a maximum of only eight faces, it is possible to dedicate one pin to each face and then set it high or low depending on whether the face has been recognized. The resulting block diagram looks like this with one connection (plus ground) for each face between the two computers.
A resistor is placed on each line to prevent damage in the event a connection from HIGH to LOW or PWR to GND is inadvertently made. A downside to the approach is that GPIO pin connections equal to the number of persons being recognized are being utilized and information is limited to HIGH / LOW. On the other hand it is fast, reliable, and is easy to implement.
In the photo below the Raspberry Pi 3B+ with camera is on the far left and connected to a breadboard with 3 LEDs that are turned on when the Python script running OpenCV detects one of three faces. It is also connected to the second Pi center bottom which displays the name of the person detected on the display. Ultimately this second Raspberry Pi will create / display the art that has been selected for that particular person.
GPIO and Python on the Raspberry Pi
The two commonly used libraries on the Raspberry Pi for use with Python are GPIO Zero and RPi.GPIO which will be used here. The sole reason for using RPi.GPIO is that I have used it in the past and was fairly sure I could get it to work. The following is all that is needed to initiate the GPIO and set a pin.
import RPi.GPIO as GPIO print("Setting pins using the board header numbering") frank = 36 margot = 38 doll = 40 GPIO.setmode(GPIO.BOARD) GPIO.setup(frank, GPIO.OUT) GPIO.setup(margot, GPIO.OUT) GPIO.setup(doll, GPIO.OUT) GPIO.output(frank, GPIO.LOW) GPIO.output(margot, GPIO.LOW) GPIO.output(doll, GPIO.LOW)
In the script running OpenCV the output is made HIGH when a face is detected and turned off on the next pass through the loop. In the setup photographed above a separate LED flashes for each detected face and the second Raspberry Pi detects it using the same library: The RPi.GPIO library also allows interrupts so that polling is not required.
The following video demonstrates the setup working.
Upcoming Work
- Improvements to the cabinet
- Obtain training photographs for all the faces and perform training
- Fabricate a small board to connect the two Raspberry Pi computer
- Write Python script to drive the monitor and control the art output
- Develop / obtain art
If you made it this far, thanks for reading and your thoughts and comments are always appreciated. In particular, using GPIO to communicate seems unorthodox and thoughts on that are welcome.
Other Posts in this Series
PiCasso Design Challenge: Adapting Art to Ages Blog #1
PiCasso Adapting Art to Viewers: OpenCV Face Detection, Blog #2
Top Comments