Professional Documents
Culture Documents
BY:
SINGOEE SYLVESTRE SHESHAI
F17/1454/2011
Project report submitted in partial fulfillment of the requirement for the award of
the degree of Bachelor of Science in Electrical and Electronic Engineering of the
University of Nairobi
1
DECLARATION OF ORIGINALITY
1) I understand what plagiarism is and I am aware of the university policy in this regard.
2) I declare that this final year report is my original work and has not been submitted elsewhere
for examination, award of a degree or publication. Where other people’s work or my own work
has been used, this has properly been acknowledged and referenced in accordance with the
University of Nairobi’s requirements.
3) I have not sought or used the services of any professional agencies to produce this work.
4) I have not allowed, and shall not allow anyone to copy my work with the intention of passing
it off as his/her own work.
5) I understand that any false claim in respect of this work shall result in disciplinary action, in
accordance with University anti-plagiarism policy.
Signature: ………………………
Date: …………………………….
CERTIFICATION
This report has been submitted to the Department of Electrical and Information Engineering,
University of Nairobi with my approval as supervisor:
Sign…………..……………………………… Date……………………………………
i
DEDICATION
ii
ACKNOWLEDGEMENTS
I would like to thank God for guiding me throughout my academic journey and to acknowledge
my supervisor, Mr. Oscar Ondeng’, for his undying support, priceless motivation and guidance
throughout the project duration.
Moreover, I extend my sincere gratitude to all the lecturers and non-teaching staff of the
Department of Electrical and Information Engineering for their contribution towards the success
of this work.
The role my friends played during the entire period cannot also go unmentioned. Thank you all
for your moral support and encouragement. I am deeply honored and indebted to you all.
To my family (Dories, Magic, Mikwa and mum), I appreciate the support you have given me
throughout my academic journey. This quest has not been easy but you have always solemnly
stood by my side. I say thank you.
iii
ABSTRACT
The proposed security solution hinges on our novel integration of cameras and motion detectors
into web application. Raspberry Pi operates and controls motion detectors and video cameras for
remote sensing and surveillance, streams live video and records it for future playback. This
research is focused on developing a surveillance system that detects strangers and to response
speedily by capturing and relaying images to owner based wireless module.
This Raspberry Pi based Smart Surveillance System presents the idea of monitoring a particular
place in a remote area. The proposed solution offers a cost effective ubiquitous surveillance
solution, efficient and easy to implement.
This project will also present the idea of motion detection and tracking using image processing.
This type of technology is of great importance when it comes to surveillance and security. Live
video streams will therefore be used to show how objects can be detected then tracked. The
detection and tracking process will be based on pixel threshold.
Keywords: Embedded System, Raspberry PI, Surveillance System, Motion Detection, tracking,
video processing
iv
TABLE OF CONTENTS
DECLARATION OF ORIGINALITY….………………………………..………………...i
DEDICATION………………..…………………….………………….…………………..ii
ACKNOWLEDGEMENTS……….……….……………………………….……………..iii
ABSTRACT……………………………………………………………………………….iv
TABLE OF CONTENTS……………………………………………………….….………v
LIST OF FIGURES………………………………………………………………………viii
LIST OF TABLES…………………………………………………………………………ix
ABBREVIATIONS……………………….………………………………………………..x
CHAPTER ONE………………………………………………………………………...….1
1.1. General Background……………………………………………………………..…..1
1.2. Problem Statement …………………………………………………………………..2
1.3. Objectives…….…………………………………………………………………..….2
1.4 Scope of the Project…………..………………..……………………………………..2
1.5 Justification…………………………………………………………………………...3
CHAPTER TWO……………………………………………………………………………4
2.1 Related works on security systems…………………………………………………...4
2.2 Evolution of Security…………………………………………………………………5
2.3 Security Systems Definition………………………………………………………….6
2.4 Current Security Technologies………….…………………………………………….6
2.4.1 Arduino Based Home Security System…….………………………………….6
2.4.1.1 How it Works……..…………….…….……………………………..6
2.4.2 CCTV Surveillance System…………………………...………………………7
2.4.2.1 Operation of CCTV System………………………………...……….7
2.4.3 Remote Surveillance IP System……………………………………...………..7
2.4.4 Raspberry Pi Based Surveillance System…………………………...…………7
2.4.4.1 Why RPI Security System for Homes?...............................................8
2.5 Image Processing…………………………………………………………….…..9
2.5.1 Image Processing Techniques………………………………………….9
v
2.5.1.1 Image Blurring…………………………………….………….9
2.5.1.2 Grayscalling……………………………………….………….9
2.5.1.3 Thresholding………………………………………………...10
2.5.2 Object Detection and Tracking………………………………………..11
2.5.3 Methods of Detection and Tracking…………………………………..12
2.5.3.1 Background Subtraction Method…………………………...12
2.5.3.2 Real time Background Subtraction and Shadow Technique..12
2.5.3.3 Template Matching………………………………………….12
2.5.3.4 Shape Based………………………………………………...12
2.5.3.5 Optical Flow Method…………………………………….....12
2.6 The Raspberry Pi……………………………………………………………..…13
2.6.1 The Raspberry Pi Models………………………………………….….13
2.6.2 Programming the Raspberry Pi……………...………………….…….15
2.6.3 Raspberry Pi Operating Systems…………...………………….……..15
2.6.4 The Pi Camera Module…………………..………………….……….15
2.7 Passive Infrared Sensor…………………………………………….…………..16
2.7.1 Principle of Operation of a PIR Sensor………………………………17
2.7.2 Reading the PIR Sensor………………………………………………17
2.7.3 Changing the Sensitivity of the PIR Sensor…………………………..18
2.7.3.1 Timeout Consideration………………………………….......18
2.7.4 Example Applications of the PIR Sensor……………………………..19
CHAPTER THREE ………………………………………… ………………….………...20
3.1 Resources………………………………………….………………….………….20
3.2 Design Hardware…………...…………………….………………….…………..20
3.2.1 Raspberry Pi Model B+……………….………………….……..……..20
3.2.1.1 Booting Up the RPI Model.…………………….…...……....20
3.2.1.2 Setting up internet connection on the RPI…….…….……….20
vi
3.2.1.3 Enabling the Pi Camera……………………………………….21
3.2.2 PIR Sensor Setup………………………………………………………..22
3.2.3 Automatic Light Simulation…………………………………….……….23
3.3 Hardware Architecture…………………………………………………….………23
3.4 Design Software…………………………………………………………….……..24
3.4.1 The Flowchart of the RPI Based Security System……………….……...24
3.4.1.1 System Initialization and Configuration……………….……...24
3.4.1.2 Generating and Sending E-mail…………………………..……25
3.4.1.3 Pseudocode………………………………………………..…...26
3.4.1.4 Developing the Full Code Listing………………………….….26
3.4.2 OpenCv - Python Video Processing………………………………….…26
3.4.2.1 Flowchart……………………………………………………...27
3.4.2.2 Pseudocode…………………………………………………....27
CHAPTER FOUR………………………………………………………………………….28
4.1 RESULTS………………………………………………………………………....28
4.1.1 Detection Using a PIR Sensor…………………………………………..29
4.1.2 Detection and Tracking Using Camera………………………………….29
4.1.2.1 Real Time Video Captions From Camera…………………….30
4.2 ANALYSIS OF THE RESULTS…………………………………………………32
4.3 CONCLUSION……..…………………………………………………………….33
4.4 RECOMMENDATIONS…………………………………………………………34
CHAPTER FIVE…………………………………………………………………………...35
5.1 REFERENCES……………...……………………………………………….…....35
5.2 APPENDICES…………………………………………………………………….37
5.2.1 Appendix (i)……………………………………………………………...36
5.2.2 Appendix (ii)……………………………………………………………..42
5.2.3 Appendix (iii)………………………………………………………….....44
vii
LIST OF FIGURES
viii
LIST OF TABLES
ix
ABBREVIATIONS
x
11
CHAPTER ONE
The demands on video surveillance systems are rapidly increasing in the present day. One of the
first things people will want to know about their surveillance system is whether or not they have
the ability to connect to it over the internet for remote viewing. In the past, security systems had
to be monitored by a guard who was locked away in a room all day watching the monitors to
make sure that nothing would happen. The other option was to come back and review the footage
but damage could have happened. Therefore, researchers and scientists had to come up with
ways of overcoming that and thus improving security at large.
Commercial spaces, universities, hospitals, casinos and warehouses require video capturing
systems that have the ability to alert and record beside live video streaming of the intruder. The
advancements in video surveillance technology have made it possible to view your remote
security camera from any internet-enabled PC or smartphone from anywhere in the word. This
encompasses the use of CCTV (DVRs) systems and IP cameras. This technology is awesome but
its cost of implementation has proven to be an impediment especially for a small home
application.
Therefore, new innovative technology revolves around affordability of a product in terms of its
cost and ease of implementation. The Raspberry Pi crosses both criteria in that it is a cheap,
effective computer which can be interfaced with other modules to realize systems with immense
functionality. A lot can be done on it ranging from motor speed control, automatic lighting, VPN
server, security system etc. [1] [2]. The latter is of great interest in this project.
The Raspberry Pi microcomputer is capable of implementing a cost effective security system for
various applications. This new arising technology related to security provides a comfortable and
safe environment for small homes. The various objectives of the system are to detect an intruder,
take an image of the intruder and also convey an alert message to the facility owner. In doing so
it thus allows for remote monitoring of homes from anywhere in the world.
The system to be designed cannot wholly replace the role of CCTV and IP surveillance cameras
especially in large commercial set ups but will make it easy for low income home owners to
monitor their homes at a very affordable price. In addition to the fact that the Raspberry Pi board
is cheap, the camera to be used in this case is relatively cheap compared to the others. The whole
security system circuitry is simple and easy to implement.
Image processing is a term which indicates the processing on image or video frame which is
taken as an input and the result set of processing is may be a set of related parameters of an
image. The purpose of image processing is visualization which is to observe the objects that are
not visible. Analysis of human motion is one of the most recent and popular research topics in
digital image processing. In which the movement of human is the important part of human
detection and motion analysis, the aim is to detect the motions of human from the background
image in a video sequence. It also includes detection and tracking [2]. The process of object
1
tracking is segmenting a region of interest from a video frames and keeping track of its motion
and position.
The need to develop a cost effective surveillance system through innovative technology
immensely influenced the development of this project. This project will design and implement a
security system based on Raspberry Pi microcomputer. The system should be able to detect
motion (intruder), activate a camera to take frames of video after motion is sensed and then send
an alert to the facility owner through electronic mail plus an image attachment.
The cost of installation of any security system depends on several factors. First, the type of
camera being used is of great consideration. A typical digital camera e.g. CCTV and IP camera
with an LCD costs about US $ 450 [25] (different brands can differ on prices) while the
Raspberry Pi SBC together with its camera module is estimated at US$ 80[25].
Another aspect of this project is to present an idea of monitoring and tracking of an intruder
through the use of a camera. Any object passing through the field of view of camera will be
detected then tracked in case the object attempts to move any body part.
1.3 Objectives
To study and describe how the Raspberry Pi can be interfaced with a motion
detector and Pi camera.
To study how a Raspberry Pi can be programmed so as to be able to send an email
to a prescribed mailhub.
To develop and build a prototype of the surveillance system based on the
Raspberry Pi SBC.
To design and implement a motion detecting and tracking system for real time
video analysis.
This project is focused on developing a surveillance system that detects motion and to respond
speedily by capturing an image and relaying it to an administrator device through the internet
platform. The system will require Raspberry Pi module, motion detection sensor, camera and
2
internet connection. It will come up with an implementation of a surveillance system which
presents the idea of monitoring a particular place in remote areas. The system can be monitored
by the user form anywhere in the world.
However, this project will not attempt to design the motion detection device, camera or the
Raspberry PI. It will therefore use these systems together with a suitable program script to
accomplish a real time surveillance system as desired.
1.5 Justification
The security system to be designed in this project can be used extensively to monitor facilities by
owners. The owner shall be able to monitor their property from wherever they are in the world. It
will not replace the use of CCTV and camera surveillance systems but reduce the cost of
implementation of a basic security system. This thus will enable small home owners to secure
their facility at a cheaper cost.
3
CHAPTER TWO
2.1 Related Works on security Systems
In the present day, researchers and developers have come up with a wide range of surveillance
systems that are used for remote monitoring, alerting as well as controlling tasks through
affordable and easy to implement hardware systems. Some have so far been realized while others
still remain a proposition.
An embedded home surveillance system which assesses the implementation of a cost effective
alerting system based on small motion detection was presented by Padmashree A. Shake and
Sumedha S. Borde. They worked on implementing cheap in price, low power consumption; well
utilize resources and efficient surveillance system using a set of various sensors. Their system
helps to monitor the household activities in real time from anywhere and based on
microcontroller which is considered nowadays as a limited resource and an open source solution
compared to SBC[3].
D. Jeevanand worked on designing of a networked video capture system using Raspberry Pi. The
proposed system works on capturing video and distributing with networked systems besides
alerting the administration person via SMS alarm as required by the client. Their system was
designed to work in a real-time situations and based on Raspberry Pi SBC. Contrasting to other
embedded systems their real-time application offers client video monitor with the help of alerting
module and SBC platform[4].
Sneha Singhd and his team described IP Camera Video Surveillance system using Raspberry Pi
technology. The Researchers aimed at developing a system which captures real time images and
displays them in the browser using TCP/IP. The algorithm for face detection is being
implemented on Raspberry Pi, which enables live video streaming along with detection of human
faces. The research did not include any of surveillance reactions[5].
Mahima F. Chauhan and Gharge Anuradha offered to design and develop a real time video
surveillance system based on embedded web server Raspberry PI B+ Board. Their system has
low cost, good openness and portability and is easy to maintain and upgrade. Thus this
application system provides better security solutions. This system can be used to effect security
in banking halls, industry, environment and in military arts[6].
Jadhav G. J evaluates in 2014 the use of various sensors, wireless module, microcontroller unit
and finger print module to formulate and implement a cost effective surveillance system. He and
his team adopted an ARM core as a basis processor of the system. PIR sensor is used to detect
motion in the vision area, while vibrating sensor is used to sense any vibration events such as
sound of breaking. The intruder detection technique is proposed by using the PIR sensor that
detect motion and trigger a system of alerting and sending short message service through GSM
module for a specified phone number. Their work can be featured by adopting numerous diverse
kinds of demanding database and thus it will be more secure and difficult to hack[7].
4
In 2014, Sanjana Prasad and his colleagues worked on developing a mobile smart surveillance
system based on SBC of Raspberry Pi and motion detector sensor PIR. Their development boosts
the practice of portable technology to offer vital safety to our daily life and home security and
even control uses. The objective of their research is to develop a mobile smart phone home
security system based on information capturing module combined with transmitting module
based on 3G technology fused with web applications. The SBC will control the PIR sensor
events and operates the video cameras for video streaming and recording tasks. Their system has
the capability to count number of objects in the scene[8].
Uday Kumar worked on implementation of a low cost wireless remote surveillance system using
Raspberry Pi. Conventional wireless CCTV cameras are widely used in surveillance systems at a
low cost. He and his team implemented a low cost and secure surveillance system using a camera
with Raspberry Pi and the images acquired have to be transferred to the drop box using a 3G
internet dongle. This was successfully implemented using Raspberry Pi and 3G dongle[9].
Security literally means a way or method by which something is secured through a system of
interworking components and devices. On the other hand, security systems are networks of
integrated electronic devices working together with a central control panel to protect against
burglars and other potential intruders[12]. Security systems work on the simple concept of
securing entry points into a home with sensors that communicate with a control panel or
command center installed in a convenient location. The sensors are typically placed in entrances
as well as easily accessible windows. A typical home security system has the following
components: A control panel, which is the primary controller of a security system, door and
window sensors, motion sensors, wired or wireless security cameras, high-decibel siren or alarm
and window stickers [11].
5
2.4 Current Security Technologies
This security system project deals with the design and development of a theft control system for
home, which is being used to prevent/control any theft attempt. The developed system makes use
of an embedded system comprising of an open hardware microcontroller(Arduino) and a modem
based on Global System for Mobile communication (GSM) technology[13].
The designed and developed system can be installed in the home. An interfacing intrusion-
detector unit is also connected to the microcontroller-based security system. The system thus
incorporates a passive infrared sensor (PIR) for motion detection. In case of an intrusion attempt,
a warning message is being transmitted by the system (as an sms) to the owner’s mobile phone,
or to any pre-configured mobile phone number for further processing.
The security system comprises of an Arduino Uno microcontroller, a standard SIM900A based
GSM/GPRS modem and PIR sensor. The whole system can be powered from any 12VDC/2A
power supply unit/battery.
Its working principle can be analyzed from the block diagram of fig 1.1. When input power is
applied to the system, the system goes into standby mode. However, when the terminals of
connector joining PIR with the Arduino microcontroller are short circuited, the preprogrammed
warning message is automatically transmitted to the concerned mobile number. This system
however does not transmit the image of the intruder. It only conveys a notification message.
6
2.4.2 Closed-circuit television (CCTV) Security System
Video surveillance is the use of video cameras to transmit a signal to a specific place, on a
limited set of monitors. It differs from broadcast television in that the signal is not openly
transmitted, though it may employ point to point (P2P), point to multipoint, or mesh wireless
links.[14] In the U.S. the first commercial closed-circuit television system became available in
1949, called Vericon[15].
The simplest system is a camera connected directly to a monitor by a coaxial cable with the
power for the camera being provided from the monitor[16]. The outdoor or indoor camera take
several images per second and thus cannot be differentiated by human eye. The images are then
transferred via a coaxial cable or optic fibre to a computer placed in a secure location. This
computers are monitored by security personnel and responds to any improper behaviors’[17].
These systems have been incorporated with alarm systems so as to send out an alert in case of a
security bridge.
Two types of CCTV storage exist; VCR and DVR. The DVR system is more superior as it can
be able to transmit digitized video signals over the data networks and thus can allow for remote
control and monitoring of the system.
Improved ability for remote viewing and control. Anyone on the network can potentially
see video from any camera connected to the network.
IP storage makes it possible to store data in any geographic location.
Greater ease of distribution. An image of a crime suspect, for example, can be
immediately distributed to officials.
The ability to connect to email and other communications systems so that alerts can be
sent automatically.
A raspberry pi can be used to implement a security system with motion detection, image
processing and alert mechanism. The alert ought to contain a time lapse photo or video and
transmitted over the internet. This thus will enable the users to monitor the homes from
anywhere in the world.
7
Figure 2: Raspberry Pi based Security System [19]
As shown in the figure above, the whole architecture of the system is composed of five modules
namely:
The role of each module shall be discussed in detail later in this chapter.
Several criteria have been used to select a security system required to safeguard a facility. The
chief among all these has been the cost of implementation of such a system. The Raspberry Pi is
also a very versatile device whose functionality is not limited. It can be extended from being
merely a security device to temperature control device, automatic lighting and proxy server. The
following reasons explain the need to have your home security system based on Raspberry Pi:
An IP Camera system has the ability to distribute alarm messages over the internet as
well as the Raspberry Pi based security system. However, the cost of an IP Camera
makes it not easily affordable to small home owners.(insert cost plus citation) Thus they
can be deployed in large industrial set ups, defence forces, police departments etc.
Arduino microcontroller based security system can be relatively cheaper to implement as
compared to Raspberry Pi based system but its memory capacity renders it more
ineffective especially when trying to interface with other modules e.g. camera, monitors,
motion sensors, mouse and keyboard. Raspberry Pi has an extendable SD card storage
and can be expanded to suit the needs of an individual. Moreover, Arduino
8
microcontroller requires a GSM modem to enable it transfer information through the
internet. The Raspberry Pi has a port to connect it to the internet.
A CCTV surveillance system is expensive to purchase and install compared to the system
in question. It requires a DVR system to connect it to the data networks through TNP/IP.
A DVR on its own is very expensive. Hence such a system may not be afforded by low
income home owners.
…………………………………………………………. (1)
2.5.1.2 Grayscalling
Grayscale is a range of shades of gray without apparent color[22]. The darkest possible shade is
black, which is the total absence of transmitted or reflected light. The lightest possible shade is
white, the total transmission or reflection of light at all visible wavelengths [22]. Intermediate
shades of gray are represented by equal brightness levels of the three primary colors (red, green
and blue) for transmitted light, or equal amounts of the three primary pigments (cyan, magenta
and yellow) for reflected light[23].
In the case of transmitted light (for example, the image on a computer display), the brightness
levels of the red (R), green (G) and blue (B) components are each represented as a number from
decimal 0 to 255, or binary 00000000 to 11111111. For every pixel in a red-green-blue ( RGB)
grayscale image, R = G = B. The lightness of the gray is directly proportional to the number
representing the brightness levels of the primary colors. Black is represented by R = G = B = 0 or
R = G = B = 00000000, and white is represented by R = G = B = 255 or R = G = B = 11111111.
Because there are 8 bits in the binary representation of the gray level, this imaging method is
called 8-bit grayscale[20].
9
Figure 3: Original and gray images [19]
2.5.1.3 Thresholding
10
The above can be achieved through the implementation of the algorithm below:
A very widely used method which is simple to implement by just subtracting the current frame
from previous frame and obtaining threshold value of difference between given pixel value and
obtained pixel value [24]. If threshold value is greater than the given the pixel it is considered as
foreground. This method is not as appropriate as it is highly inaccurate and gives false rate
detection.
11
2.5.3.2 Real Time Background Subtraction and Shadow
Detection Technique Theory
It describes two type of distortion namely brightness distortion and chromaticity distortion based
on RGB values of pixels in given image. This method is accurate up to some extends as it also
detect the shadow part of object [23].
Template Matching is probably the best method for some specific environment. It's the most
accurate although sometimes there is lack of originality in object detected. Object can be
detected for one specific video using a template cropped from the video. However, there is no
guaranteed accuracy because all that is known is the best match for each frame; no scanning is
done on the percentage template matches the frame. It only works if the object is always in the
video, otherwise it will create a false detection [23].
Shape based method is used to detect objects in real-world images. The shape features are more
striking as compared to local features like SIFT because most object categories are better
described by their shape then texture, such as cows, horses and cups and also for wiry objects
like bikes, chair or ladders, local features contain large amount of background noise. Thus shape
features are often used as a replacement to local features [23].
Sequences of ordered images allow the estimation of motion as either instantaneous image
velocities or discrete image displacements. The optical flow methods try to calculate the motion
between two image frames which are taken at times t and at every voxel position. These
methods are called differential since they are based on local Taylor series approximations of the
image signal; that is, they use partial derivatives with respect to the spatial and temporal
coordinates [23].
For a 2D+t dimensional case (3D or n-D cases are similar) a voxel at location (𝑥, 𝑦, 𝑡) with
intensity 𝐼(𝑥, 𝑦, 𝑡) will have moved by , and between the two image frames, and the
following brightness constancy constraint can be given[23]:
…………………………………… (2)
………………………………………………… (3)
12
or
……………………………………………… (4)
This results in
…………………………………………………….. (5)
Thus:
…………………………………………………………….. (6)
or
………………………………………………………………… (6)
The Raspberry Pi is a Linux based microcomputer based on ARM architecture[24]. It was built
mainly to aid in developing open source game. The device is estimated to cost about $35 [30]
depending on the model.
13
Figure 7: The Raspberry Pi [25].
a) Model B+/B
First release was made in July 2014. This Model is an upgrade of the Model B. It has the
following characteristics: 4 USB ports, 40 pins on the GPIO header , Improved power circuitry
which allows higher powered USB devices to be attached and now hot-plugged. The full size
composite video connector of Model B has been removed and the functionality moved to the
3.5mm audio/video jack and the full size SD card slot of Model B has also been replaced with a
much more robust microSD slot[25]. The following details some of the improvements 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
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
14
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.
b) Model A/A+
This is the basic device, with a single USB port and 256MB of SDRAM. Onboard ports include:
Full size SD card, HDMI output port, Composite video output, One USB port, 26 pin expansion
header exposing GPIO, 3.5mm audio jack, Camera interface port (CSI-2), LCD display interface
port (DSI) and One microUSB power connector for powering the device[25].
To enable communication with the outside world, the Raspberry Pi has to be programmed with a
suitable programming language. These languages include Java, FOTRAN, Pascal, Python, C,
C++ etc.[26]. Each language has its own syntax and semantics. RPI can be programmed using
any of these languages but for purposes of this project, Python will be of great importance to
study. It is provided by default through and thus optimum operation of the Pi can be achieved.
An operating system makes Raspberry Pi run. Since Raspberry Pi is a credit sized computer that
is based on Linux, optimum performance of RPI can be achieved if it is therefore operated in this
environment. Raspbian provides more than a pure OS: it comes with over 35,000 packages, pre-
compiled software bundled in a nice format for easy installation on RPI[25]. Important to note is
that the Raspberry Pi does not operate in a Windows environment. To get access to Pi from
windows we require Putty Software. Putty is an SSH and TelNet client.
The Camera Board on the Raspberry Pi is a small printed circuit board with a camera on it.
The PCB is connected to a ribbon cable which connects to the Pi itself on its own port. The
ribbon can be extendable. The camera on the board is very small (5MP camera)[25]. As for now
it is the only Camera made specifically for the Pi therefore these specifications cannot be
updated. Since it uses 250mA, externally powering the Pi should be sufficient enough for the
camera[27].Specific configuration settings are required to initialize the camera plus a Python
script to enable it take pictures.
15
Figure 8: Pi Camera module[25].
16
Figure 9: Operation of a PIR sensor[29].
17
Figure 10: Controlling the PIR sensor from an Arduino Microcontroller [30].
On Adafruit PIR sensors, there's a little trim potentiometer labeled TIME. This is a 1 MΩ
adjustable resistor which is added to a 10K series resistor[30]. And C6 is 0.01uF so;
If the R_time potentiometer is turned all the way down counter-clockwise (to 0 ohms) then[30];
18
2.7.4 Example Applications of the PIR sensor
In order to allow for email notifications to send, the OS needs a program that allows for emails to
be sent[31]. Simple Mail Transfer Protocol (SMTP) is a program that allows a system to deliver
an email from a local computer to a mailhost. It does not receive mail but can send out mail.
SMTP is ideal for situations where alerts are needed to be sent, therefore it is useful when
sending notifications.
A python script can be used to achieve this. It may just send a notification without image or can
be modified to send an attachment along with the alarm message[17]. For SMTP to support
transmission of an attached file, Multipurpose Internet Mail Extension (MIME) is required.
19
CHAPTER THREE
3.1 Resources
For an embedded real-time surveillance system to be utilized for effective monitoring and
alerting, the system has to have at least three functions. These functions are: detection, image
processing and alert mechanism. This Raspberry Pi based security system is thus composed of
mainly two parts. These are: design hardware and design software
Raspbian ‘Wheezy’ image was written into the 4GB Micro SD card. This was the operating
system chosen to run on the Pi because the OS has been optimized and ported to the Raspberry
Pi ARM architecture. This OS has very good integration with the hardware and comes pre-
loaded with a GUI and development tools.
After slotting in the Micro SD card and connecting RJ45 Ethernet cable to the Pi and the
personal computer with Putty software (Putty is an SSH client used to remotely access and
control the Pi from computer running on Windows platform) the system was powered. Putty was
then started and the default static IP address of the Pi was typed into the host name field. While
doing this, windows pc was set to manual IP configuration. This was to allow it communicate
with the Raspberry Pi.
Internet was necessary in so that the Pi can communicate over network protocols and thus allow
for installation of necessary Python packages. The architecture below was used to achieve that.
20
Figure 11: internet set up architecture
Since the broadcast router uses Dynamic Host Configuration Protocol (DHCP) to dish out IP
addresses to devices connected to it, it was necessary to change the IP address of the Pi from
static to dynamic. This was done by editing the network interfaces file using the command;
sudo nano /etc/network/interfaces
This is the camera made specifically for the Raspberry Pi. It was hooked to the raspberry pi
through CSI-2 electrical port which is an extremely fast port. To configure and enable the
camera, the following commands were executed at the CLI of the raspberry pi:
sudo raspi-config
21
After these configuration settings, the system was rebooted. This was done to ensure that the
camera was allocated enough space in memory. The camera takes 5MP image and has a
resolution of 1080 by 890. And to ensure that the camera was well configured and functional, the
following command was executed.
This by default this command takes a three second image and save it in a file called image.png.
This is formed the prime motion sensor. It was used to control the entire system. The device used
here was HC501SR passive infrared sensor. The detection range is 7 meters by 140(degrees)
coning angles. It has a delay time of 16 seconds but adjustable. The ambient temperature is
253K-323K. It was powered directly from the Pi through the 5V dc supply pin. Its output was
connected as the input to the programmable GPIO pin.
An LED was used to simulate an automatic light control. This was designed to be controlled
through the action of a PIR sensor. This device was connected to the GPIO pin through a 220Ω
resistor.
22
Figure 13: Hardware Architecture of the Security Systems Based on Raspberry Pi.
23
3.4 Design Software
This following flowchart was used to design and thus document the security systems project. It
illustrates the series of events starting from intrusion event up to the point when it sends out an
alert. This algorithm was implemented using a Python script. Figure 3.4 below presents the basic
flowchart of the entire system.
24
a) Read a Channel
In order to read the value of any GPIO pin, simply type; GPIO.input(channel)
b) Drive a channel
In order to drive a channel of GPIO pin, type; GPIO.output(channel, status)
This sequence of events can be elaborated well using the block diagram below.
After configuring the system to send an alert to the predefined subscriber, it was then necessary
to generate and send the mail. Multipurpose Internet Mail Extension (MIME) package was then
called and used to generate the attachment. MIME supports characters other than ASCII, non –
text attachments (audio, video and application programs) etc. It thus extends the format of an
email. Simple Mail Transfer Protocol (SMTP) program was then used to deliver the email from
the Raspberry Pi to the configured mailhub. This can be summarized using the blocks below.
25
3.4.1.3 Pseudocode
i. Upon restart of the system, send out email with boot IP assigned to a mailhost.
ii. Check the status of the GPIO pin. If the pin is LOW, GPIO output pin 13 should remain
LOW and the system is idle. Else if the pin suddenly goes HIGH. Interpret this as an
interrupt event.
iii. While the value of the input GPIO pin is HIGH (interrupt event), set pin 13 to be HIGH.
This instance blinks the LED. Call the function that starts the Pi Camera.
iv. Camera takes a 10 seconds video and save it in a file.
v. The system checks whether the internet is enabled on the Raspberry Pi.
vi. If internet, send email to a prescribed mailhost. If no internet, wait for 5 seconds then
check again.
Reset the PIR sensor pin to LOW and recheck again the status after 2 seconds. This should return
the program to the main loop.
To be able to develop the Python script that executes the algorithm defined in the flowchart, the
following were done at the CLI of the Raspberry Pi:
The Pi was started and a directory was created using mkdir command
Inside the directory, a file was created using the touch command and made executable
using sudo chmod +x (filename).
The nano command was then used to open the editor and the full Python code was
written there. The script was executed using the following command:
OpenCv is a very powerful tool used to analyze images and video files. The basic processing
procedure to be followed is detailed in the flowchart below. Thresholding as a technique of
image processing was chosen for the implementation of motion detection and tracking in video
streams. The choice to script using OpenCv – Python was because Python on its own does not
support video processing. There is so far no video processing library in Python. OpenCv thus
provided the necessary platform to achieve image processing. The following flowchart was used
for this implementation
26
Figure 16: Flowchart of motion detection and tracking algorithm
3.5.1 Pseudocode
27
CHAPTER FOUR
4.1 RESULTS
Tweaking the sensitivity of the PIR sensor among different levels, the following were the results:
Sensitivity = maximum
15 OFF NO NONE
10 NO NONE
OFF
8 NO NONE
OFF
6 YES YES Fig. 4.4
Sensitivity = medium
Table 2: Results for medium sensitivity of the PIR sensor
15 OFF NO NONE
10 OFF NO NONE
8 OFF NO NONE
6 OFF NO NONE
5 ON NO NONE
28
3 ON YES Fig. 4.4
Sensitivity = Low
15 OFF NO NONE
10 NO NONE
OFF
8 OFF NO NONE
6 OFF NO NONE
5 OFF NO NONE
4 NO NONE
OFF
3 YES Fig. 4.4
ON
Pixel
threshold 0 5 10 20 25 30 50 80 100
Motion
detection NO YES YES YES YES YES YES YES NO
29
4.1.2.1 Captions Showing detection and tracking using camera in real time video
Threshold level = 25
Figure 17: Motion detection and tracking in real-time video stream. Result when the object
in the field of view of the camera was stationary.
30
Threshold level = 25 pixels
Figure 18: Result showing the tracking upon motion of an originally stationary object.
31
Threshold = 100 pixels
Figure 19: Result for detection and tracking at a threshold level of 100 pixels. This was
obtained irrespective of motion of the object
Executing the Python script in appendix (i) successfully yielded the results indicated in tables 1-
3. It can be depicted that the range of detection of the PIR sensor varies at different sensitivity
levels. The higher the sensitivity of the sensor the higher the range of detection
Referring again to the results in tables 1-3, it can be safely said that the PIR sensor formed the
primary motion detector and hence the first line of defense. All the other modules solely
32
depended on the PIR GPIO pin to go HIGH. In case this sensor fails, the whole security
procedure as designed shall fail.
The send alerts from this part are provided in appendix section. They show the email send to a
mailhost through SMTP protocol. The attached file is a 10 second video that shall be analyzed in
order to explain the concept of image processing in real time video.
Running the Python-OpenCv code provided in appendix (ii) did not yield successful results in
the RPI. This was because a large video file or otherwise live video streams require large
processor speed. The RPI runs at 700MHz. This script was thus implemented differently on the
laptop PC. The results in table 4 were obtained.
From those results in table 4, it can be deduced that varying the pixel threshold of the camera
achieves the action of detection and tracking. However, detection occurs only within some limits.
This can be shown by comparing the captions indicated in Figures 18 - 20. At a pixel threshold =
25, Motion detection and tracking was achieved, while at 100 pixels (Figure 20), no detection
nor tracking was possible. In Figure 16, 𝑓𝑛 and 𝑓𝑛−1 represents the amount of pixels for the
previous object and amount of pixels for the current object.
4.3 CONCLUSSION
The project designed and implemented a security system based on the Raspberry Pi. The aspects
of the system are: motion detection using a PIR sensor, video capturing using a Pi Camera and
sending out an alert through e-mail. It did not however achieved the option of image processing
in the Raspberry Pi because of system constraints i.e. processor speed.
4.4 RECOMMENDATIONS
33
CHAPTER FIVE
5.1 REFERENCES
[1] Z. Sundas, “Motion Detecting Camera Security System with Email Notifications and Live
Streaming Using Raspberry Pi.” .
[2] M. Peter and H. David, “Learn Raspberry Pi with Linux,” Apress, 2012.
[3] P. S. Dhake and B. Sumedha S., “Embedded Surveillance System Using PIR Sensor.,” vol.
No. 02, no. 3, 2014.
[4] J. D., “Real Time Embedded Network Video Capture And SMS Alerting system,” Jun.
2014.
[5] S. Sneha, “IP Camera Video Surveillance using Raspberry Pi.,” Feb. 2015.
[6] F. C. Mahima and A. Prof. Gharge, “Design and Develop Real Time Video Surveillance
System Based on Embedded Web Server Raspberry PI B+ Board. International Journal of
Advance Engineering and Research Development (Ijaerd), NCRRET.,” pp. 1–4, 2015.
[7] J. G. J, “Design and Implementation of Advanced ARM Based Surveillance System Using
Wireless Communication.,” 2014.
[8] P. Sanjana, J. S. Clement, and S. R., “Smart Surveillance Monitoring System Using
Raspberry PI and PIR Sensor.,” 2014.
[9] U. Kumar, R. Manda, S. Sai, and A. Pammi, “Implementation Of Low Cost Wireless Image
Acquisition And Transfer To Web Client Using Raspberry Pi For Remote Monitoring.
International Journal of Computer Networking, Wireless and Mobile Communications
(IJCNWMC).,” vol. No. 4, no. 3, pp. 17–20, 2014.
[10] “The History of Security _ PerspecSys.com.htm.” .
[11] A.-D. Osama, “Cisco IP Video Surveillance Introduction,” Cisco Expo, 2009.
[12] “What is a security system and how does it work _ SafeWise.htm.” .
[13] T.K. Hareendran, “GSM Home Security Alarm System With Arduino,” Library Security
System, 2014. .
[14] R. Verman, “Distance Education In Technological Age,” Anmol Publ. Pvt Ltd, p. 166,
2005.
[15] “Television Rides Wires,” Pop. Sci., no. February, p. 179, 1949.
[16] “Introduction to Closed Circuit Television,” Jan-2013. .
[17] B. Messauod, Access Control Systems: Secuiry, Management and Trust Models., 1st ed.
Austin, TX, USA: Springer, 2006.
[18] “IP Surveillance,” IT Encyclopedia. .
[19] “ijcsit2014050648.pdf.” .
[20] B. E. Reddy, M. Veeresha, and N. Rao, “Image Processing: A Survey.”
[21] A. Ambrosetti and P. H. Rabinowitz, “Dual variational methods in critical point theory and
applications,” J. Funct. Anal., vol. 14, no. 4, pp. 349–381, 1973.
[22] “113-115-OBJECT-DETECTION-AND-TRACKING-USING-IMAGE-
PROCESSING.pdf.” .
[23] “Simon_Denman_Thesis.pdf.” .
[24] S. Prasad, P. Mahalakshmi, A. J. C. Sunder, and R. Swathi, “Smart Surveillance Monitoring
System Using Raspberry PI and PIR Sensor,” Int. J. Comput. Sci. Inf. Tech., vol. 5, no. 6,
2014.
[25] Raspberry Pi for Begginers, 2014th ed. London UK.: Imagine Pulishing Ltd.
34
[26] B. J. Glenn, Computer Science: An Overview, 11th ed. Edwards Brothers.
[27] “The Raspberry Pi Education Manual,” Dec. 2012.
[28] “How Infrared Motion Detector Components Work,” Glolab Corporation., 2013.
[29] “pir-passive-infrared-proximity-motion-sensor.pdf.” .
[30] G. Honey, Intruder alarms, 2nd ed. Oxford ; Burlington, MA: Newnes, 2003.
[31] “The Raspberry Pi Education Manual,” no. 1.0, Dec. 2012.
35
5.2 APPENDICES
Pure Python code used to implement the RPI based security system. This is the code that
was executed in the Pi .
#!/usr/bin/env python
#gmail settings
toaddrs = 'sheshaisylvestre@yahoo.com'
username = 'singoee93@gmail.com'
fromaddrs = 'singoee93@gmail.com'
password = 'sylvestre'
36
smtpserver.starttls()
smtpserver.ehlo()
smtpserver.login(username, password)
ip_lines = data[0].splitlines()
split_lines_a = ip_lines[1].split()
split_lines_b = ip_lines[1].split()
ip_type_a = connect_type(split_lines_a)
ip_type_b = connect_type(split_lines_b)
ipaddr_a = split_lines_a[split_lines_a.index('src')+1]
ipaddr_b = split_lines_b[split_lines_b.index('src')+1]
msg1 = MIMEText(my_ip_a)
msg1['Subject'] = 'BOOT IP'
msg1['From'] = 'singoee93@gmail.com'
ip_lines = data[0].splitlines()
split_lines_a = ip_lines[1].split()
split_lines_b = ip_lines[1].split()
ip_type_a = connect_type(split_lines_a)
ip_type_b = connect_type(split_lines_b)
ipaddr_a = split_lines_a[split_lines_a.index('src')+1]
ipaddr_b = split_lines_b[split_lines_b.index('src')+1]
msg1 = MIMEText(my_ip_a)
msg1['Subject'] = 'BOOT IP'
msg1['From'] = 'singoee93@gmail.com'
msg1['To'] = 'toaddrs'
37
smtpserver.quit()
time.sleep(10)
filename = 'my_camera.h264'
camera.start_preview()
time.sleep(1)
print 'Taking Video..Wait'
camera.start_recording(filename)
camera.wait_recording(10)
38
camera.stop_recording()
print 'Video taken..checking for internet connectivity.'
fromaddrs = 'singoee93@gmail.com'
password = '**********'
username = 'singoee93@gmail.com'
toaddrs = 'sheshaisylvestre@yahoo.com'
39
fp.close()
att.add_header('Content-Disposition','attachment',
filename=filename)
msg.attach(att)
filename=filename)
msg.attach(att)
except e:
print ("not connected")
if True:
print("Wait...")
time.sleep(5)
stri = "https://www.google.co.in"
data = urllib.urlopen(stri)
else:
40
print "Sending mail ...."
41
5.2.2 Appendix (ii)
# if the frame could not be grabbed, then we have reached the end
# of the video
if not grabbed:
break
42
currentFrame = gray
continue
previousFrame = currentFrame
currentFrame = gray
# compute the absolute difference between the current frame and
# first frame
frameDelta = cv2.absdiff(previousFrame, gray)
thresh = cv2.threshold(frameDelta, 100, 255, cv2.THRESH_BINARY)[1]
43
5.2.3 Appendix (iii)
Send mail
Received mail
Fig 4.4: Result showing an email notification sent from gmail to yahoo mail
44