This repo is a web camera app with object dection based on raspberry pi
Software Stack: Flask + Tensorflow lite + OpenCV
Hardware requirement:
- respberry pi 3b
- picamera module
$ cd ~
$ virtualenv env_webcam --python=python3
$ source env_webcam/bin/activate
(env_webcam) $ cd ~
(env_webcam) $ git clone https://github.com/brunolinux/WebCam.git
(env_webcam) $ cd WebCam
(env_webcam) $ pip install -r requirements.txt
Note: If you want to run this demo on your raspberry pi board, the opencv library is obligatory. You can reference to the steps below.
the format is like below:
- WEBSITE: flask port number
- GMAIL: send raspberry pi's IP address by mail
- ADMIN: administrator name and password
[WEBSITE]
Port = portnumber
[GMAIL]
Username = your.mail@gmail.com
Password = passwd
Sender = sender.mail@gmail.com
Receivers = receivers.mail@mail.com
[ADMIN]
Username = user
Password = passwd
Reference: Install Opencv 4 on your Raspberry Pi
Note: For the consideration of stability, here we use the 3.4.3 version. But the procedure of compilation is same.
You can make sure whether the compilation is successful by running the following code
(env_webcam) $ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
Then you can open a browser and input the ip address of your raspberry pi borad (with port 8000
). You can see the image with object detection results
Note: if you want to use the port 80
, run the script using administrator account
$ cd ~/WebCam
$ sudo ../env_webcam/bin/python app.py
$ sudo apt-get install supervisor
$ cd ~/WebCam
$ sudo cp ./conf/supervisor_webcam.conf /etc/supervisor/conf.d/
The reboot the board.
Reference: TensorFlow Lite for Raspberry Pi
Note: Because the tensorflow lite is not stable yet, we found a bug in the file <root dir of tensorflow code>/tensorflow/lite/tools/make/Makefile
:
In my board, the root directory of tensorflow source code is /home/pi/tensorflow/
Below is the modified code:
CORE_CC_ALL_SRCS := \
$(wildcard tensorflow/lite/*.cc) \
$(wildcard tensorflow/lite/*.c) \
$(wildcard tensorflow/lite/c/*.c) \
$(wildcard tensorflow/lite/core/*.cc) \
$(wildcard tensorflow/lite/core/api/*.cc)
The developer ignores one line: $(wildcard tensorflow/lite/core/*.cc) \
, so just add it.
This bug has been fixed
The just follow the step of native compiling of the above article.
If the compilation succeeds, you can find the static library libtensorflow-lite.a
in the directory <root dir of tensorflow code>/tensorflow/lite/tools/make/gen/rpi_armv7l/lib/libtensorflow-lite.a
. That's what we need.
Note:
- If you have more interests, you can also test the binary file
label_image
andbenchmark_model
on the raspberry pi board. - I have tried to compile the runtime python library of tensorflow lite. But there is still many bugs by present. So I decided to test firstly the C++ version of tensorflow lite.