raspberry-pi-documentation-opencv (1)
raspberry-pi-documentation-opencv (1)
8/23/2019 Page 1
Human Count by Date-Time
3.0
3.00 3.00 3.00 3.00
2.5
1.5
0.5
0.00 0.00
0.0
12:17:00 PM 12:18:00 PM 12:19:00 PM 12:20:00 PM 12:21:00 PM
Date Time
1/1
»» Raspberry Pi is the name of a series of single-board computers made by the Raspberry Pi Foundation, a UK charity
that aims to educate people in computing and create easier access to computing education.
»» Raspberry Pi operates in the open source ecosystem: it runs Linux (a variety of distributions), and its main
supported operating system, Raspbian, is open source and runs a suite of open source software. NOOBS is an easy
operating system installer which contains Raspbian. We are using Raspbian GNU/Linux 10 (buster) version 10.
»» We have used Raspberry Pi 3 Model B+ (2018) and Arducam camera module for Raspberry Pi. Pi-camera can be
connected to the raspberry pi as an add-on accessory which will be used for object detection research.
»» This will take up a significant amount of space on the Micro SD card of your Raspberry Pi.
»» This demonstration can be done utilizing SSH which allows you to operate your Raspberry Pi, but we will do this
with physical access to the Raspberry Pi terminal.
»» Follow the instructions on the tutorial. Once you have installed all the supportive libraries and pip, you will create
your virtual environment. It is important to get this step right because you will create the OpenCV in the virtual
environment. Once downloaded, OpenCV will only be accessible in this virtual environment.
»» Virtual environment is a python component that creates an isolated environment for python projects. This means
that each project can have its own dependencies, regardless of what dependencies every other project have. Virtual
environment by the name ‘cv’ is created to download OpenCV in this document.
»» It can be challenging to download OpenCV or Tensorflow on raspberry pi since it’s important to have the right
versions installed and also using the command line can be foreign concept.
»» Open:
$$ nano ~/.profile
»» Once in the profile, copy and paste the command for the virtual environment and virtual environment wrapper to
the end of the command explanation:
»» The next step will access your virtual environment so that you can build the OpenCV in it.
$$ source ~/.profile
»» Reserve a few hours for this step. This is when OpenCV will install onto your Raspberry Pi.
»» Continue on to finish the tutorial and feel free to follow along with the practice example given.
»» In this example we see how human face can be detected and from a live video feed to record the presence of
number of humans present in the frame and detect their movement. It is further used to record number of face
detected in the room at a given time which is stored in Amazon web server and visualize it on Power BI through
MySQL workbench.
»» We have followed the blog post by Pyimagesearch on Simple object detection and customized the data being
collected. You can find the link to the bold post here- https://www.pyimagesearch.com/2018/07/23/simple-object-
tracking-with-OpenCV/
»» Step 1 : Activate the Virtual Environment (cv) and navigate to the folder location using command line. Further deploy
the python file along with its caffe model (Caffe model is a deep learning framework). Since this example uses
argument parser, caffe model and prototxt files can be replaced with the latest suitable library available on OpenCV
online.
$$ source ~/.profile
$$ workon cv
$$ cd ~/simple-object-tracking # folder name found inside user folder pi
$$ python object_tracker.py --prototxt deploy.prototxt --model res10_300x300_ssd_iter_140000.caffemodel
»» Important snippets from the python file and further customization of the code to collect data is noted below.
»» MySQLdb is imported along with datetime to record the time to the database. MySQLdb has to be downloaded
on virtual environment (cv). Downloading mysql-client, mysql-connector, mysql-connector-python on the virtual
environment cv helped us to successfully import MySQLdb statement and execute the python script.
»» Below snippet shows the connection to database and the data formated according to the table that is created in
MySQLdb.
»» This is printing the values that is being uploaded to the database on the terminal at an regular time interval of 2
seconds. Data recorded is also being uploaded every two second
»» This example fall short in few ways. Although it is detecting human face, the centroid tracker is not accurate with
respect to object movement. Also proximity of background subtraction done is not precise to locate farther objects
with pi-camera.
»» In this example we see how person can be detected and from a live video feed to record the presence of number
of humans present in the frame and detect their movement. It is further used to record number of people detected
in the room at a given time which is stored in Amazon web server and visualize it on Power BI through MySQL
workbench.
»» We have followed the blog post by Pyimagesearch on Filter object detection and customized the data being
collected. You can find the link to the bold post here- https://www.pyimagesearch.com/2018/05/14/a-gentle-guide-
to-deep-learning-object-detection/
»» Step 1 : Activate the Virtual Environment (cv) and navigate to the folder location using command line. Further deploy
the python file along with its caffe model (Caffe model is a deep learning framework). Since this example uses
argument parser, caffe model and prototxt files can be replaced with the latest suitable library available on OpenCV
online.
»» Important snippets from the python file and further customization of the code to collect data is noted below.
$$ source ~/.profile
$$ workon cv
$$ cd ~/filter-object-detection # folder name found inside user folder pi
$$ python filter_object_detection.py --prototxt MobileNetSSD_deploy.prototxt.txt --model MobileNetSSD_deploy.
caffemodel
»» MySQLdb is imported along with datetime to record the time to the database. MySQLdb has to be downloaded
on virtual environment (cv). Downloading mysql-client, mysql-connector, mysql-connector-python on the virtual
environment cv helped us to successfully import MySQLdb statement and execute the python script.
»» Object detection is counted for data collection and since we are have ignore all the other objects we are just
counting humans.
»» Cameraid (line 78) is a constant value that records the pi-camera and its respective Raspberry Pi being used. In this
example we are extracted values from a single Pi.
»» Line 80-82 is collecting date and time.
»» Below snippet shows the connection to database and the data formated according to the table that is created in
MySQLdb.
»» This is printing the values that is being uploaded to the database on the terminal at an regular time interval of half a
second. Data recorded can be set at 2 seconds which is good enough to analyze for machine learning.
»» Note that time.sleep line is used at other places to start the object detection and end the detection. It is important
to set this statement associated with mySQLdb data collection as well.
»» To stop the python file from running the object tracking click on the video frame and ‘q’ on the keyboard as it is set
as the break key in the code.
»» You will have to have your own MySQL Server and password at
which point you can open and load MySQL Workbench.
»» Select “Get Data,” from which you can pick MySQL database to
extract your data from. You will need to log in to your server
again.
8/23/2019 Page 1
Human Count by Date-Time
6
4
Person Count
0.0 0.0
0
12:17:00 PM 12:18:00 PM 12:19:00 PM 12:20:00 PM 12:21:00 PM
Date Time
1/1