sudo apt-get update sudo apt-get install python3-picamera python3-pil python3-opencv libjpeg-dev libfreetype6 libfreetype6-dev zlib1g-dev libwebp-dev libopenjp2-7-dev libatlas-base-dev fonts-freefont-ttf git
sudo pip3 install --upgrade numpy sudo pip3 install imutils
sudo pip3 install https://github.com/google-coral/pycoral/releases/download/v2.0.0/tflite_runtime-2.5.0.post1-cp37-cp37m-linux_armv7l.whl
git clone https://git.jonathan.struebel-family.net/robot-club/pibot/lesson5.git
cd lesson5
curl -L 'https://tfhub.dev/tensorflow/lite-model/efficientdet/lite0/detection/metadata/1?lite-format=tflite' -o efficientdet_lite0.tflite curl -L 'https://storage.googleapis.com/download.tensorflow.org/models/tflite/edgetpu/efficientdet_lite0_edgetpu_metadata.tflite' -o efficientdet_lite0_edgetpu.tflite
python3 webstreaming.py
Replace the text “pibot##” with the label on the pibot
Verify that the PiBot detects objects in front of the camera by drawing a box around them
cd osoyoowebcar sudo python3 webcar.py
Replace the text “pibot##” with the label on the pibot
The webstreaming.py file is another Flask app that streams images from the CSI Camera connected to the Raspberry Pi to your web browser after searching for objects within the image.
If you need a refresher on what decorators are, review Lesson 4
outputFrame is a global buffer that stores exactly one image from the camera. The cv2.imencode function converts (encodes) an image frame into a standard format, in this case the JPEG format
The yield function temporarily stops the loop that it's in and returns the data that is passed as a parameter to the yield function.
The while loop reads each image from the camera, performs object detection on it, draws boxes around the objects, and prints some statistics on the image before saving the image to the global outputFrame buffer
The detector variable is an instance of the ObjectDetector class. It get initialized on line 127
The detect_objects function is run as a separate thread. Look at line 221 to see how to do that. Threads are a powerful way to allow different functions in the code to run in parallel. Using threads can help your code run faster.
When self is used in front of a function call it is referring to a function defined within that same class
The detect function uses the Tensorflow Lite (or TFLite) library to run machine learning neural networks that process data and provide information about what is in that data. Tensorflow Lite was developed by Google. Learn more about machine learning and neural nets in Algorithm Explanation.
sudo shutdown -h now