This project aims to identify diverse objects and animals through Python, TensorFlow, and OpenCV, executed on a Raspberry Pi running Ubuntu.
The algorithm for object recognition with OpenCV and TensorFlow follows a streamlined process. Initially, an input image is fed into the neural network built on TensorFlow, which extracts features and patterns. OpenCV is then employed to preprocess and enhance the image, facilitating better analysis. The model categorizes objects based on learned patterns, assigning probabilities to each class. Post-processing in OpenCV refines the results, eliminating noise and optimizing accuracy. This collaborative synergy between TensorFlow and OpenCV enables the system to robustly identify objects in real-time on the Raspberry Pi, combining the strengths of both libraries for efficient and reliable object recognition.
Raspberry Pi 4
SD card (Raspbian Configured)
Raspberry Pi Adapter
Webcam
Laptop / PC
Display
Keyboard
Mouse
Micro HDMI cable
Install just the TensorFlow Lite interpreter
sudo apt-get update
sudo apt-get dist-upgrade
Thanks, EdjeElectronics! They made a GitHub repository that contains the shell script making the installation easier
git clone https://github.com/EdjeElectronics/TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi.git
Once you have downloaded it. We will rename it to make it easier to work with:
mv TensorFlow-Lite-Object-Detection-on-Android-and-Raspberry-Pi tflite1
cd tflite1
Now, we will create a virtual environment that avoids any versioning conflicts between libraries.
sudo pip3 install virtualenv
After it has install we create an environment and active it
python3 -m venv tflite1-env
source tflite1-env/bin/activate
Once we are inside the virtual environment we install TF Lite and OpenCV dependencies:
bash get_pi_requirements.sh
We then install the standard or max version of libedgetpu library. The difference isn’t that far
std: I got a max of 23 FPS
sudo apt-get install libedgetpu1-std
OR
max: I got a max of 26 FPS
sudo apt-get install libedgetpu1-max
Max has a faster FPS, but it does heat up the Coral. I kept the standard instead of max.
At this point, you can select your own model or use Google’s sample TF model to check if it is working correctly.
Once it has downloaded we need to unzip it
unzip coco_ssd_mobilenet_v1_1.0_quant_2018_06_29.zip -d Sample_TFLite_model
At this point, we can run the sample by to test the set up by running (inside our environment)
python3 TFLite_detection_webcam.py --modeldir=Sample_TFLite_model
P.S - While the system effectively identifies and labels recognized objects, its accuracy isn't flawless. Occasionally, it may misidentify objects and provide incorrect names, as evident in the picture featuring Benji, the boss. Despite these occasional quirks, I appreciate Benji's cooperation during the testing process, remaining calm and not barking.