0% found this document useful (0 votes)
90 views

Chapter 1

This document discusses developing a motion detection system using a Raspberry Pi. It will use a camera to capture images when unusual activity is detected by sensors. The captured images will be sent to a mobile device in real-time via IoT. This allows a user to be notified of potential crimes and see pictures of intruders. The system provides low-cost home security compared to expensive professional security systems. A literature review found that previous studies developed theft detection systems using IoT, object tracking with Raspberry Pi cameras, and people counting using computer vision algorithms.

Uploaded by

Raju Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views

Chapter 1

This document discusses developing a motion detection system using a Raspberry Pi. It will use a camera to capture images when unusual activity is detected by sensors. The captured images will be sent to a mobile device in real-time via IoT. This allows a user to be notified of potential crimes and see pictures of intruders. The system provides low-cost home security compared to expensive professional security systems. A literature review found that previous studies developed theft detection systems using IoT, object tracking with Raspberry Pi cameras, and people counting using computer vision algorithms.

Uploaded by

Raju Raj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

MOTION DETECTION USING RASPBERRY PI

Chapter 1

1.0 INTRODUCTION TO IOT

In this modern era of Internet of Things (IoT) we have all existing new
technologies to transform our life into simple means, it's a significant idea to
expand a system which can be restrained and observe from anywhere. This will be
an intelligent surveillance system which can be used for security point of view. The
main cause of this project is to design and develop a system that scans or monitors
the area in which it is executed. This system can be used in the area where there
will be no access to enter, also in area where we need to detect the unusual activity.
In this system a camera and different sensors have been used. The camera is used
to capture the images of unusual behavior happening in different direction. The
captured images are stored in USB or in particular folder in raspberry-pi for further
investigation. The images will be useful to work on then. As the sensors detect any
motion, the captured images are sent to mobile through IOT. So that the user will
get aware of crime taking place and will get real time image of things taking place.
Then the user can take necessary action. There are other categories of good quality
security systems and cameras for home security but they are much expensive. So,
we will setup a low cost easy to implement simple Raspberry Pi based theft
detection System, which not only alert consumer but also sends the picture of
Intruder.

The main telemetry framework was turned out in Chicago path in 1912. It is said to
have utilized phone lines to screen information from power plants. Telemetry
extended to climate observing during the 1930s, when a gadget known as a
radiosonde turned out to be generally used to screen climate conditions from
inflatables. In 1957 the Soviet Union propelled Sputnik, and with it the Space

ECE- 1SP18EC0 Page|1


MOTION DETECTION USING RASPBERRY PI

Race.

ECE- 1SP18EC0 Page|2


MOTION DETECTION USING RASPBERRY PI

This has been the section of aviation telemetry that made the premise of our
worldwide satellite interchanges today.

Expansive selection of M2M innovation started during the 1980s with wired
associations for SCADA (supervisory control and information obtaining) on the
production line floor and in home and business security frameworks. In the 1990s,
M2M started pushing toward remote advancements. ADEMCO fabricated their
own private radio system to address interruption what's more, smoke location since
sprouting cell network was as well costly. In 1995, Siemens presented the principal
cell module worked for M2M.

The Internet of Things might be a hotly debated issue in the business however it is
anything but another idea. In the mid 2000's, Kevin Ashton was laying the
preparation for what might turn into the Internet of Things (IoT) at MIT's AutoID
lab. Ashton was one of the pioneers who imagined this idea as he scanned for ways
that Delegate and Gamble could improve its business by connecting RFID data to
the Internet. The idea was basic yet amazing. On the off chance that all articles in
everyday life were furnished with identifiers and remote network, these articles
could be speak with one another and be overseen by PCs.

ECE- 1SP18EC0 Page|3


MOTION DETECTION USING RASPBERRY PI

CHAPTER 2

2.0 LITERATURE REVIEW

Montaser N. Ramadan et. al. proposed objective of fleet monitoring and


management. The system has two units: the main is the security unit consisting of a
GSM, GPS, relay, current sensor and microcontroller. The current sensor will
transmit an analog signal to the controller whenever the car is moving and
confirmation is done by sending SMS to the owner.

Karan Siyal et.al. proposed the framework acknowledges the message and through
CAN Bus broadcasts the message to the whole vehicle network. The exact location
will be send to the owner within very less time. The GSM modem interfaced to the
microcontroller gets the message, the yield of which enacts a component that
cripples the ignition of the vehicle by using flow sensor which results in stopping
of the vehicle.

Pengfei Zhou et. al. depicted a system to alert the user if the unauthorized person
tries to take away the vehicle and stop the ignition and deactivate the gadget.

D. Jiang, V. Taliwal et. al. proposed a car security system involved with a GPS and
a GSM module. The user connects through this substructure with vehicles and
decides their present areas and status using Google Earth and the position of
alerted vehicles can be followed by client.

B.G. Nagaraja et.al. proposed motors of vehicles are controlled using GSM and
microcontroller. The secret word which has been declared needs to be sorted out
for the vehicle to start. At the point when the secret word coordinates then and at
exactly

ECE- 1SP18EC0 Page|4


MOTION DETECTION USING RASPBERRY PI

that point ignition of the vehicle will begin. Every time secret key neglects to
match up to the three trials then framework will starts the siren and it will send the
message to the owner through GSM system.

Geoffrey Gordon presented a paper on “Better Motion prediction for people


tracking”. In this paper, he proposed a movement demonstrate for individuals
following that is roused by the objective arranged nature of individuals'
development. This movement show includes a learning segment that enables it to
utilize data about individual’s normal directions in a particular domain to learn
objective areas. The objective areas are upgraded so ways delivered by an
organizer concur well with the preparation directions. Ways arranged from the area
of a man being followed to these objectives are utilized by the movement refresh to
extend the speculations forward in time. He looked at the execution of the
movement model to a basic Brownian movement display inside the system of a
molecule channel based individual’s tracker. Exploratory outcomes checked that
the movement demonstrate performed better, making a more practical
dissemination over positions.

Badhan Hemangi presented a paper on “PEOPLE COUNTING SYSTEM USING


RASPBERRY PI WITH OPENCV”. In this approach the framework checks the
number of individuals passing through a virtual door by using a Pi-camera
mounting vertically on the raspberry Pi board with Python programming device
connected to the application but the framework needs a ton of upgrades to be truly
dependable.

Mingxiu Zhang presented the paper on “Real time tracking passing people using a
single camera” In this approach he examined about the location and following of
passing individuals by utilizing the bi-directional projection histogram of

ECE- 1SP18EC0 Page|5


MOTION DETECTION USING RASPBERRY PI

histogram and furthermore utilized two casing contrasting techniques for different
individual’s division.

ECE- 1SP18EC0 Page|6


MOTION DETECTION USING RASPBERRY PI

M.Manikandan, R.Balamurali presented a paper on “Real time People Tracking


and counting system using Fuzzy Logic” which shows efficient and reliable
approach to automatic people segmentation, tracking and counting, used in
surveillance systems using an improved mode algorithm to obtain the regions of
static background and novel fuzzy background subtraction approach regions for
background subtraction.

Nitesh Sanklecha presented the paper on “Motion Detection and Tracking of a


Leopard in a Video”. In this paper, it represents two different scenarios for tracking
of an object in a video sequence. Using the Horn-Schunck algorithm for motion
estimation gave fair results, but it cannot eliminate in noise. But using Lucas –
Kanade algorithm gave the best results compared to earlier algorithm with noise
removal. The disadvantage of this method is there are some discontinuities
observed while determining the Optical Flow pattern.

K.Shiva Prasad and M.Shirisha presented the paper on “Human Face Detection and
Tracking Using Raspberry PI Processor” which explains the techniques for human
face detection and tracking in real time using a modified version of algorithm
suggested by Paul viola and Michael Jones. It is based on object detection by
extracting some specific features from the image.

P. Angelov et.al. proposed a project focused on the basis to implement the object
detection and tracking based on its color, which is a visual based project i.e., the
input to the project will be the video/image data which is continuously captured
with the help of a webcam which is interfaced to the Raspberry Pi. It will detect the
object and it tracks that object by moving the camera in the direction of the
detected object.

Samreen Amir et. al. The proposed system performed according to its expectation.

ECE- 1SP18EC0 Page|7


MOTION DETECTION USING RASPBERRY PI

The Raspberry pi offers better size but less speed. Accuracy of both systems was

ECE- 1SP18EC0 Page|8


MOTION DETECTION USING RASPBERRY PI

similar even if the FPS rate is very different. Our algorithm can be implemented to
almost any marine environment given the task for which it is designed for.

From the literature review it is observed that theft detection using IOT makes our
life more comfortable by monitoring through camera and detecting any person or
intruder. IoT has been gradually bringing a sea of technological changes in our
daily lives, which in turn helps to making our life simpler and more comfortable,
though various technologies and applications. There is innumerable usefulness of
IoT applications into all the domains including medical, manufacturing, industrial,
transportation, education, governance, mining, habitat etc. Automatic human
detection and tracking is an important and challenging field of research and is
having many applications in it.

ECE- 1SP18EC0 Page|9


MOTION DETECTION USING RASPBERRY PI

CHAPTER 3

3.0 Design of IOT based Motion Detection System


The block diagram of IOT Based Motion detection system using Raspberry PI
shown in fig.3.1. IOT Based Motion detection system, sensor detects movement
and gives detected signal to raspberry pi to take identified camera image, the
framework utilizes picture preparing to identify a definite region of movement
event and features it as needs be. The framework currently transmits the pictures
of the event over IOT to be seen by the client on the web.

Fig.3.1 Block diagram for IOT Based Theft Detection and monitoring system

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

3.1 Hardware Configuration


For implementing this project, we are using the following

Raspberry Pi

Raspberry Pi Camera

Display

3.1.1 Raspberry Pi
The Raspberry Pi is a Linux and ARM based microcomputer which was built
mainly to provide developing open source game. Raspberry pi is a little credit card
measured PC fit for performing different functionalities, for example, in
observation frameworks, military applications, and so on. The working framework
utilized here is Raspbian OS. Raspbian OS must be introduced with the goal that
the picture can be transmitted to the advanced mobile phone

3.1.1.1 The Raspberry Pi Models


This part portrays the models of Raspberry Pi accessible. This report won't
endeavor to give full particulars yet an outline so as to help in settling on a choice
with regards to which gadget it is required to achieve the targets being referred to.
As of now, five Raspberry Pi models do exist. They are: Model B+, Model A+,
Model B, Model A and the Compute Module (as of now just accessible as a major
aspect of the Compute Module advancement unit). Every one of these models
utilize the equivalent SoC (System on Chip - consolidated CPU and GPU), the
BCM2835, yet other equipment highlights contrast. There are a few models of
Raspberry Pi, and for a great many people Raspberry Pi 4 Model B is the one to
pick. Raspberry Pi 4 Model B is the.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Fig 3.2 Raspberry Pi 4

3.1.1.2 Model B+/B


First release was made in July 2014. This Model is a redesign of the Model B. It
has the accompanying attributes: 4 USB ports, 40 pins on the GPIO header ,
Improved force hardware which permits more powerful USB gadgets to be
connected and now hot-stopped. The full size composite video connector of Model
B has been expelled and the usefulness moved to the 3.5mm sound/video jack and
the full size SD card space of Model B has likewise been supplanted with a
considerably more vigorous micro SD slot. The accompanying subtleties a portion
of the upgrades over the Model B: Current monitors on the USB ports mean the B+
now supports hot- plugging.

Current limiter on the 5V for HDMI means HDMI cable-powered VGA


converters work in all cases.

14 more GPIO pins

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

EEPROM readout support for the new HAT expansion boards

Higher drive capacity for analog audio out, from a separate regulator,
which means a better audio DAC quality

No more back powering problems, due to the USB current limiters


which also inhibit back flow, together with the "ideal power diode"

Composite output moved to 3.5mm jack Connectors now moved to two


sides of the board rather than the four of the original device

Ethernet LEDs moved to the Ethernet connector

4 squarely-positioned mounting holes for more rigid attachment to cases.

3.1.1.3 Programming the Raspberry Pi


To empower correspondence with the outside world, the Raspberry Pi must be
modified with an appropriate programming language. These dialects incorporate
Java, FOTRAN, Pascal, Python, C, C++ etc. Every language has its own sentence
structure and semantics. RPI can be modified utilizing any of these dialects
however for motivations behind this venture, Python will be vital to contemplate. It
is given naturally through and in this way ideal activity of the Pi can be
accomplished.

3.1.1.4 Raspberry Pi Operating Systems


A working framework makes Raspberry Pi run. Since Raspberry Pi is a credit card
sized PC that depends on Linux, ideal execution of RPI can be accomplished in the
event that it is along these lines worked right now. Raspbian gives in excess of an
unadulterated OS: it accompanies more than 35,000 bundles, pre-gathered
programming packaged in a decent configuration for simple establishment on RPI.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Essential to note is that the Raspberry Pi doesn't work in a Windows situation. To


gain admittance to Pi from windows we require Putty Software. Clay is a SSH and
TelNet customer.

3.1.2 The Pi Camera Module


The Camera Board on the Raspberry Pi is a little printed circuit board with a
camera on it. The PCB is associated with a lace link which interfaces with the Pi
itself on its own port. The lace can be extendable. The camera on the board is
extremely little (5MP camera). With respect to now it is the main Camera made
explicitly for the Pi in this way these determinations can't be refreshed. Since it
utilizes 250mA, remotely controlling the Pi ought to be adequate enough for the
camera. Specific setup settings are required to instate the camera in addition to a
Python content to empower it take pictures.

Fig 3.3 Raspberry Pi Camera

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

3.2 SOFTWARE MODULE

The proposed framework is based Linux working framework as a software


platform. It is essentially made out of a few capacity modules.

The primary capacity of every module is as per the following.

• System initialization and setting module.


• Daytime observing.
• Sensor persistent inspecting module.
• Image preparing module: the target of this module is to recognize the caught
object in the observing scheme.
• Image transmission module: It's utilized to pass the picture to the principle
administrator observing framework utilizing remote correspondence media.

3.2. 1 Software tools


3.2.1.1 NOOBS
Noobs is intended to make it simple to choose and introduce working frameworks
for the Raspberry Pi without stressing over physically imaging SD card. On first
boot NOOBS will format your SD card and permit you to choose which OS as you
need to introduce from a rundown. This OS list is naturally created from both
locally accessible OS and those accessible from remote archive.

3.2.2 Putty

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Putty is a free and open-source terminal emulator, serial console and network file
transfer application. It supports a few system conventions, including SCP, SSH,
Telnet, rlogin, and raw socket connection. It can likewise interface with a serial
port.

3.2.3 OpenCV

Open CV is an Open-source Computer Vision is popularly known as the Swiss


army knife of computer vision. It has a wide varieties of modules. Using these
modules we can get solutions for problems in computer vision. The best part of
OpenCV is its architecture and memory management. It provides a framework
within which it is possible to work with images and videos in any number of ways.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Let us see how to compile and install OpenCV 4 on your Raspberry Pi. OpenCV 4
was officially released on November 20th, 2018. It is also possible to pip install
OpenCV as well! As of this update however, PyPi does not contain precompiled
OpenCV 4 binaries which can be installed via pip. Therefore, if you want OpenCV
4 then you’ll need to compile from source. To learn how to install OpenCV 4 on
your Raspberry Pi, just follow steps. Install OpenCV 4 on your Raspberry Pi
In this project, we’re going to install OpenCV 4 on your Raspberry Pi. OpenCV 4
has a goal of reducing bloat, adding optimizations, and updating the deep learning
module.

From there, we’ll walk through 7 steps to compile and install OpenCV 4 on your
Raspberry Pi. Compiling from source allows us to have full control over the
compile and build. It also allows us to grab the latest code — something that pip
and apt-get don’t offer.

Finally, we’ll test our OpenCV 4 install on our Raspberry Pi with a fun project. If
we don’t already have the Raspbian Stretch OS, you’ll need to upgrade your OS to
take advantage of Raspbian Stretch’s new features. To upgrade your Raspberry Pi
3 to Raspbian Stretch, you may download it here and follow these upgrade
instructions (or these for the NOOBS route which is recommended for beginners).
The former instructions take approximately 10 minutes to download via a torrent
client and about 10 minutes to flash the SD card with Etcher or another tool. At
that point you can power up and proceed to the next section. Physical access to
your Raspberry Pi 3 so that you can open up a terminal and execute commands
Remote access via SSH or VNC. We’ll be doing the majority of this tutorial via
SSH, but as long as you have access to a terminal, you can easily follow along.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Can’t SSH? If you see your Pi on your network, but can’t ssh to it, you may need
to enable SSH. This can easily be done via the Raspberry Pi desktop preferences
menu (you’ll need an HDMI cable and a keyboard/mouse) or running sudo service
ssh start from the command line of your Pi.

After you’ve changed the setting and rebooted, you can test SSH directly on the Pi
with the localhost address. Open a terminal and type ssh [email protected] to see if it is
working. To SSH from another computer you’ll need the Pi’s IP address — you
could figure it out by looking at your router’s clients page or by running ifconfig
on the Pi itself.

Keyboard layout giving you problems? Change your keyboard layout by going to
the Raspberry Pi desktop preferences menu. I use the standard US Keyboard
layout, but you’ll want to select the one appropriate for you.

Step #1: Expand filesystem on your Raspberry Pi


To get the OpenCV 4 party started, fire up your Raspberry Pi and open an SSH
connection (alternatively use the Raspbian desktop with a keyboard + mouse and
launch a terminal).

Are you using a brand new install of Raspbian Stretch?

If so, the first thing you should do is expand your filesystem to include all
available space on your micro-SD card:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Install OpenCV 4 on your Raspberry Pi


$ sudo raspi-config
And then select the “Advanced Options” menu item:

Figure 1: Selecting the “Advanced Options” from the raspi-config menu to expand
the Raspbian file system on your Raspberry Pi is important before installing
OpenCV 4. Next we’ll actually expand the filesystem.

Followed by selecting “Expand filesystem”:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Figure 2: The Raspberry Pi “Expand Filesystem” menu allows us to take advantage


of our entire flash memory card. This will give us space necessary to install
OpenCV 4 and other packages.
Once prompted, you should select the first option, “A1. Expand File System”, hit
Enter on your keyboard, arrow down to the “<Finish>” button, and then reboot
your Pi — you may be prompted to reboot, but if you aren’t you can execute:

Install OpenCV 4 on your Raspberry Pi


$ sudo reboot
After rebooting, your file system should have been expanded to include all
available space on your micro-SD card. You can verify that the disk has been
expanded by executing df -h and examining the output:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Install OpenCV 4 on your Raspberry Pi


$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 30G 4.2G 24G 15% /
devtmpfs 434M 0 434M 0% /dev
tmpfs 438M 0 438M 0% /dev/shm
tmpfs 438M 12M 427M 3% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 438M 0 438M 0% /sys/fs/cgroup
/dev/mmcblk0p1 42M 21M 21M 51% /boot
tmpfs 88M 0 88M 0% /run/user/1000
As you can see, my Raspbian filesystem has been expanded to include all 32GB of
the micro-SD card.

However, even with my filesystem expanded, I have already used 15% of my 32GB
card.

If you are using an 8GB card you may be using close to 50% of the available
space, so one simple thing to do is to delete both LibreOffice and Wolfram engine
to free up some space on your Pi:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get purge wolfram-engine
$ sudo apt-get purge libreoffice*
$ sudo apt-get clean
$ sudo apt-get autoremove

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

After removing the Wolfram Engine and LibreOffice, you can reclaim almost 1GB!

Step #2: Install OpenCV 4 dependencies on your Raspberry Pi


From there, let’s update our system:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get update && sudo apt-get upgrade
And then let’s install developer tools including CMake:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install build-essential cmake unzip pkg-config
Next, let’s install a selection of image and video libraries — these are critical to
being able to work with image and video files:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
From there, let’s install GTK, our GUI backend:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install libgtk-3-dev
And now let’s install a package which may reduce pesky GTK warnings:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install libcanberra-gtk*

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

The asterisk will grab the ARM specific GTK.

Followed by installing two packages which contain numerical optimizations for


OpenCV:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install libatlas-base-dev gfortran
And finally, let’s install the Python 3 development headers:

Install OpenCV 4 on your Raspberry Pi


$ sudo apt-get install python3-dev
Once you have all of these prerequisites installed you can move on to the next step.

Step #3: Download OpenCV 4 for your Raspberry Pi


Our next step is to download OpenCV.

Let’s navigate to our home folder and download both opencv and opencv_contrib.
The contrib repo contains extra modules and functions which we frequently use
here on the PyImageSearch blog. You should be installing the OpenCV library
with the additional contrib modules as well.

When you’re ready, just follow along to download both the opencv and
opencv_contrib code:

Install OpenCV 4 on your Raspberry Pi


$ cd ~

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.0.0.zip


$ wget -O opencv_contrib.zip
https://github.com/opencv/opencv_contrib/archive/4.0.0.zip
From there, let’s unzip the archives:

Install OpenCV 4 on your Raspberry Pi


$ unzip opencv.zip
$ unzip opencv_contrib.zip
I also like to rename the directories:

Install OpenCV 4 on your Raspberry Pi


$ mv opencv-4.0.0 opencv
$ mv opencv_contrib-4.0.0 opencv_contrib
If you skip renaming the directories, don’t forget to update the CMake paths.

Now that opencv and opencv_contrib are downloaded and ready to go, let’s set up
our environment.

Step #4: Configure your Python 3 virtual environment for OpenCV 4


Let’s grab and install pip, a Python Package Manager.

To install pip, simply enter the following in your terminal:

Install OpenCV 4 on your Raspberry Pi


$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Make use of virtual environments for Python development


If you aren’t familiar with virtual environments, please take a moment look at this
article on RealPython or read the first half of the this blog post on PyImageSearch.

Virtual environments will allow you to run different versions of Python software in
isolation on your system. Today we’ll be setting up just one environment, but you
could easily have an environment for each project.

Let’s go ahead and install virtualenv and virtualenvwrapper now — they allow for
Python virtual environments:

Install OpenCV 4 on your Raspberry Pi


$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/get-pip.py ~/.cache/pip
To finish the install of these tools, we need to update our ~/.profile file (similar to
.bashrc or .bash_profile ).

Using a terminal text editor such as vi /vim or nano , add the following lines to your
~/.profile :

Install OpenCV 4 on your Raspberry Pi


# virtualenv and virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
Alternatively, you can append the lines directly via bash commands:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Install OpenCV 4 on your Raspberry Pi


$ echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.profile
$ echo "export WORKON_HOME=$HOME/.virtualenvs" >> ~/.profile
$ echo "export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3" >>
~/.profile
$ echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.profile
Next, source the ~/.profile file:

Install OpenCV 4 on your Raspberry Pi


$ source ~/.profile
Create a virtual environment to hold OpenCV 4 and additional packages
Now you’re at the point where you can create your OpenCV 4 + Python 3 virtual
environment on your Raspberry Pi:

Install OpenCV 4 on your Raspberry Pi


$ mkvirtualenv cv -p python3
This line simply creates a Python 3 virtual environment named cv .

You can (and should) name your environment(s) whatever you’d like — I like to
keep them short and sweet while also providing enough information so I’ll
remember what they are for. For example, I like to name my environments like
this:

py3cv4
py3cv3

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

py2cv2

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

etc.
Let’s verify that we’re in the cv environment by using the workon command:

Install OpenCV 4 on your Raspberry Pi


$ workon cv

Figure 3: The workon command is part of the virtualenvwrapper package and


allows us to easily activate virtual environments. Here I’m activating the cv
environment which we’ll install OpenCV 4 into on our Raspberry Pi.
Install NumPy
The first Python package and only OpenCV prerequisite we’ll install is NumPy:

Install OpenCV 4 on your Raspberry Pi


$ pip install numpy
We can now prepare OpenCV 4 for compilation on our Raspberry Pi.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Step #5: CMake and compile OpenCV 4 for your Raspberry Pi


For this step, we’re going to setup our compile with CMake followed by running
make to actually compile OpenCV. This is the most time-consuming step of
today’s blog post.

Navigate back to your OpenCV repo and create + enter a build directory:

Install OpenCV 4 on your Raspberry Pi


$ cd ~/opencv
$ mkdir build
$ cd build
Run CMake for OpenCV 4
Now let’s run CMake to configure the OpenCV 4 build:

Install OpenCV 4 on your Raspberry Pi


$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D ENABLE_NEON=ON \
-D ENABLE_VFPV3=ON \
-D BUILD_TESTS=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D BUILD_EXAMPLES=OFF ..

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Update 2018-11-27: Notice the -D OPENCV_ENABLE_NONFREE=ON flag.


Setting this flag with OpenCV 4 ensures that you’ll have access to SIFT/SURF and
other patented algorithms.

Be sure to update the above command to use the correct


OPENCV_EXTRA_MODULES_PATH path. If you’re following along with this
tutorial exactly you should not need to update the path.

Once CMake is finished, it’s important that you inspect the output. Your output
should look similar to mine below:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Figure 4: Ensure that “Non-free algorithms” is set to “YES”. This will allow you to
use patented algorithms such as SIFT/SURF for educational purposes.

Figure 5: The CMake command allows us to generate build files for compiling
OpenCV 4 on the Raspberry Pi. Since we’re using virtual environments, you
should inspect the output to make sure that the compile will use the proper
interpreter and NumPy.
Take a second now to ensure that the Interpreter points to the correct Python 3
binary. Also check that numpy points to our NumPy package which is installed
inside the virtual environment.

Increase the SWAP on the Raspberry Pi


Before you begin the compile I would suggest increasing your swap space. This
will enable you to compile OpenCV with all four cores of the Raspberry Pi without
the compile hanging due to memory exhausting.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Open up your /etc/dphys-swapfile file:

Install OpenCV 4 on your Raspberry Pi


$ sudo nano /etc/dphys-swapfile
…and then edit the CONF_SWAPSIZE variable:

Install OpenCV 4 on your Raspberry Pi


# set size to absolute value, leaving empty (default) then uses computed
value # you most likely don't want this, unless you have an special disk
situation
# CONF_SWAPSIZE=100
CONF_SWAPSIZE=2048
Notice that I’m increasing the swap from 100MB to 2048MB.

If you do not perform this step it’s very likely that your Pi will hang.

From there, restart the swap service:

Install OpenCV 4 on your Raspberry Pi


$ sudo /etc/init.d/dphys-swapfile stop
$ sudo /etc/init.d/dphys-swapfile start
Note: Increasing swap size is a great way to burn out your Raspberry Pi microSD
card. Flash-based storage have limited number of writes you can perform until the
card is essentially unable to hold the 1’s and 0’s anymore. We’ll only be enabling
large swap for a short period of time, so it’s not a big deal. Regardless, be sure to

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

backup your .img file after installing OpenCV + Python just in case your card dies

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

unexpectedly early. You can read more about large swap sizes corrupting memory
cards on this page.

Compile OpenCV 4
Now we’re ready to compile OpenCV 4:

Install OpenCV 4 on your Raspberry Pi


$ make -j4
Note: In the make command above, the -j4 argument specifies that I have 4 cores
for compilation. If you have compile errors or your Raspberry Pi hangs/freezes you
can try without the -j4 switch which can eliminate race conditions.

Here you can see OpenCV 4 has compiled without any errors:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Figure 6: I’ve compiled OpenCV 4 on my Raspberry Pi successfully (the make


command has reached 100%). So now I’ll issue the sudo make install command.
And from there, let’s install OpenCV 4 with two additional commands:

Install OpenCV 4 on your Raspberry Pi


$ sudo make install
$ sudo ldconfig
Don’t forget to go back to your /etc/dphys-swapfile file and:

Reset CONF_SWAPSIZE to 100MB.


Restart the swap service.
Step #6: Link OpenCV 4 into your Python 3 virtual environment
Let’s create a symbolic link from the OpenCV install in the system site-packages
directory to our virtual environment:

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Install OpenCV 4 on your Raspberry Pi


$ cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
$ ln -s /usr/local/python/cv2/python-3.5/cv2.cpython-35m-arm-linux-gnueabihf.so
cv2.so
$ cd ~
I cannot stress this step enough — this step is critical. If you don’t create a
symbolic link, you won’t be able to import OpenCV in your scripts. Also, ensure
that the paths and filenames in the above commands are correct for your Raspberry
Pi. I suggest tab-completion.

Step #7: Test your OpenCV 4 install on your Raspberry Pi


Let’s do a quick sanity test to see if OpenCV 4 is ready to go.

Open a terminal and perform the following:

Install OpenCV 4 on your Raspberry Pi


$ workon cv
$ python
>>> import cv2
>>> cv2. version
'4.0.0'
>>> exit()
The first command activates our virtual environment. Then we run the Python
interpreter associated with the environment.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

If you see that you have version 4.0.0 installed, then you’re now fully armed and
dangerous + ready to perform computer vision and image processing.

3.2.4. RASPBIAN OS
Raspbian is a free working framework dependent on Debian enhanced for the
Raspberry Pi equipment. A working framework is the arrangement of fundamental
projects and utilities that make your Raspberry Pi run.

3.2.5 PYTHON
Python is an exceptionally incredible high level, object-oriented programming
language. It is a deciphered language. Driving the Raspberry Pi's I/O lines requires
a touch of programming and Python is the most favored in light of the fact that
Raspbian comes preloaded with Python, the official programming language of the
Raspberry Pi and IDLE.
3.3 Flow chart of IOT based Theft detection & Monitoring System

The project mainly emphasizes the importance of security and privacy in all
required places and thus this project produces a satisfactory solution for a long-
term standing problem.

Stage 1: The framework is initialized and configured. The software of this


undertaking project incorporates modules, for example, Videoing module, Motion
detection module, alerting module, networking module and Web server module.
These modules are incorporated just to perceive whether the first client is utilizing
the framework or an intruder is attempting to utilize.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Stage 2: It is then sent to the picture and video processing module where the face
and traits of the individual utilizing the framework is altogether checked and
contrasted and the models that is being set by the client through a remote systems
administration channel.

Stage 3: If the face/body and the qualities coordinate with the endorsed guidelines,
at that point the alarming module gets latent and the hinder is headed to zero. In the
event that the face and trait doesn't coordinate with the measures, at that point the
hinder is headed to one and the control is given to the administrator notice
framework.

Stage 4: The picture of the intruder is caught and it is recorded.

Stage 5: This picture is then sent as an email to the client given email-id. At that
point the security enactment process is embraced. The image of the intruder is
taken and is sent to the email which will unmistakably recognize the picture of the
gatecrasher.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

Chapter 4
4. Result
4.1 Email Notification
So as to consider email notifications to send, the OS needs a program that takes
into consideration mails to be sent. Basic Mail Transfer Protocol (SMTP) is a
program that permits a framework to convey an email from a neighborhood PC to a
mail host. It doesn't get mail yet can convey mail. SMTP is perfect for
circumstances where alarms are should have been sent, in this manner it is valuable
when sending warnings. A python content can be utilized to accomplish this. It
might simply send a warning without picture or can be altered to send a connection
alongside the caution message. For SMTP to help transmission of an appended
record, Multipurpose Internet Mail Extension (MIME) is required.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

CONCLUSION

In this project we have implemented a brilliant reconnaissance framework


equipped for recording/catching video/picture and transmitting to a PDA and ftp
server. It is worthwhile as it offers unwavering quality and security on the two
sides. It is verified and encoded on the beneficiary side moreover. Thus it offers
just the individual worried to see the subtleties. Important move can be made in
limited capacity to focus time on account of crisis conditions like interruption. IOT
approach offers a substitute way to plan a dependable Security framework
contrasted with regular CCTVs. The forthright expense of the frameworks is
possibly lesser contrasted with customary frameworks. Along these lines, a
security observing framework constrained by Raspberry Pi has been actualized and
tried .The force gadgets part of the framework and the basic Python code content
were ideally planned/coded, acknowledged and tried. The usage of IOT approach
has given an ongoing observing of the objective region. A ready SMS message and
an E-mail containing the pictures of the gatecrashers are gotten momentarily inside
10 seconds. The Python code has been viably tried to redress any potential bugs. It
had the option to proficiently look at the past edges/sec and present casings every
second to identify any movement.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

References

[1] N.Sugumaran, G.V.Vijay, E.Annadevi, “Smart Surveillance Monitoring


System using Raspberry pi and pir sensor”, International Journal of Innovative
Research in Advanced Engineering (IJIRAE) ISSN: 2349-2163, Issue 04, Volume
4 (April 2017).

[2] S.Vishal, G.Prashanth, “Motion Detection Using IoT and EmbeddedSystem


Concepts”, International Journal of Advanced Research in Electrical, Electronics
and Instrumentation Engineering (An ISO 3297: 2007 Certified Organization) Vol.
5, Issue 10, October 2016.

[3] Wai Zhao, Jayanand Jegatheesan and Son Chee Loon (2015) Exploring “IOT
Application Using Raspberry Pi, InterCheanational Journal of Computer Networks
and Applications”,Vol 2, Issue 1, January - February,2015.

[4] Yi Gu1, Myoungjin Kim1, Yun Cui1and Hanku (2014) ,“An UPnP-Based
Surveillance Camera System for Home Security”, International Journal of
Distributed Sensor Networks Vol 5,2014.
[5] Padmashree A. Shake and Sumedha S. Borde(2015), “Designing Approach of
an Intruder Realtime Ubiquitous Embedded Surveillance System”, Journal of
Theoretical and Applied Information Technology Vol 79,2015.

[6] Jadhav, G. J(2014), “Design and Implementation of Advanced ARM Based


Surveillance System using Wireless Communication, International Journal of
Advance Research in Computer Science and Management Studies”Vol 2 ,2014.

[7] Khandavalli Michael Angelo and Karthik(2014), “Arm Based Remote


Surveillance and Motion Detection System by Using MJPEG Algorithm”,IEEE
Conf April 2014.

[8] Priya B. Patel, Viraj M. Choksi, Swapna Jadhav, M.B. Potdar, PhD(2016)
“Smart Motion Detection System using Raspberry Pi”, International Journal of
Applied Information Systems (IJAIS), Vol10 – No.5, February 2016.

ECE- 1SP18EC0 Page|


MOTION DETECTION USING RASPBERRY PI

[9] Telaprolu, M.K, sarma, V.V.ratankanth, E.K.Rao, SN.Banda, vehicular


Electronics and safety (ICVES), IEEE International Conference pune (2009).

[10] Muthukumar S, Dr.Krishnan .N, Pasupathi.P, Deepa. S, “Analysis of Image


Inpainting Techniques with Exemplar, Poisson, Successive Elimination and Pixel
Neighborhood Methods”, International Journal of Computer Applications (0975 –
8887), Volume 9, No.11, 2010.

ECE- 1SP18EC0 Page|

You might also like