Documentation: Object Classification and Text to Speech Functionality.
First go to directory where your project resides:
Command: “cd ~/projects/tflite1”
1. Enabling virtual environment within raspberry 4
Command:
workon pyenv
Purpose:
This command enables virtual environment in python
2. Libraries used
a. Pyttsx3: This is a text to speech engine library that enables text to speech
functionality
b. cv2(opencv): Used for capturing video, resizing frames and processing frames.
c. Numpy: used for efficient handling of multidimensional data structures like array.
d. Tensorflow: open source library used for diving into machine learning.
3. Setting up the camera.
def __init__(self,resolution=(640,480),framerate=30):
# Initialize the PiCamera and the camera image stream
[Link] = [Link](0)
ret = [Link](cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc(*'MJPG'))
ret = [Link](3,resolution[0])
ret = [Link](4,resolution[1])
# Read first frame from the stream
([Link], [Link]) = [Link]()
# Variable to control when the camera is stopped
[Link] = False
“ [Link] = [Link](0)” - Make sure to put the corresponding camera
index. Ranges between 0 - 5.
4. Text to Speech Engine Initialization
def init_engine():
engine = [Link]()
[Link]('rate', 100)
[Link]('volume',1.0)
return engine
Command to run the code:
python3 TFLite_detection_webcam.py --
modeldir=Sample_TFLite_model
Note: modeldir is the directory where your local model is stored. In your
raspi, There is directory Sample_TFLite_model directory
Troubleshooting.
1. Make sure you are in the projects directory before interacting.
2. Camera error: Make sure to place the right camera index. Refer to setting up camera
section.
3. Environment error: Error indicating module not found or library not found often refers to
the problem of not activating virtual environment. Make have activated before running
the script