people counting system using raspberry pi with opencv

people counting system using raspberry pi with opencv
International Journal for Research in Engineering Application & Management (IJREAM)
ISSN : 2494-9150 Vol-02, Issue 01, APR 2016.
1
PEOPLE COUNTING SYSTEM USING
RASPBERRY PI WITH OPENCV
1
Badhan Hemangi, 2K. Nikhita
1,2
Department Of Electronics And Telecommunication Engineering, Late G.N Sapkal College of Engineering,
Nashik, Maharashtra, India.
1
poojabadhan33@gmail.com, 2nikhitakunigiri@gmail.com
Abstract - People observation and counting is of interest in many commercial and non-commercial scenarios. The number
of people entering and leaving shops, the occupancy of office buildings or the passenger count of commuter trains provide
useful information to shop merchants and marketers, security officials or train operators. To this end, this thesis develops
a distributed people counting system using raspberry pi with openCV. A people counter is a device used to count the
number of pedestrians walking through a door or corridor. Most of the time, this system is used at the entrance of a
building so that the total number of visitors can be recorded.
Keywords – Raspberry Pi, openCV, Counting System, Sensor.
counts are also a way for libraries to increase their awareness
of how many people are using services but not checking out
material.
I. INTRODUCTION1
People counting system can be implemented in various
domains such as libraries, schools, airports, malls. In school
and public libraries, a people counting system can streamline
the following functions:
Keep in compliance – Library workers can report yearly
statistics to the state as needed. They can stay within budget
restrictions by maintaining labour percentages or limiting
technology usage.
Make cases to administration – With people counting data,
libraries can share impressive numbers with elected officials or
board members to prove their need for increased or decreased
hours of operation and additional staffing, technology or
services. They can prove that usage has increased, even if
circulation is down. By installing a door counter above the
computer lab, libraries can use traffic numbers to gauge their
building’s technology usage. They can increase or decrease the
amount of technology available based on accurate data.
Make informed business decisions – Door counters allow
libraries to learn which entrances are used most and which
rooms and times are the busiest. With this knowledge, they can
guide the placement and timing of cafes, refreshments, kiosks,
exhibits, guest speakers, study groups, etc. Accurate people
IJREAMV02I01894
www.ijream.org
Here are some of the benefits of counting people:
When traffic is fluctuating, business is fluctuating. But do you
always understand the factors that are affecting traffic? You
may think sales reports and a walk around the shopping centre
or museum tell you all about your visitors and customers. But a
people counting system is like having an army of people
looking at your building, all the time, every day of the year. We
can help you see trends. We can help you "zoom out" and
reach beyond today's sales or visitor figures. Here are some
factors that can be assessed once you
II. LITERATURE SURVEY
A People Counting Technology
People counting is a widely studied and commercially
exploited subject. This section briefly reviews the typical
technologies used for people counting.
B Video Cameras
In the authors describe an approach to people counting (and
localization) using multiple video cameras. The focus lies on
© 2016, IJREAM All Rights Reserved.
International Journal for Research in Engineering Application & Management (IJREAM) 2
ISSN : 2494-9150 Vol-02, Issue 01, APR 2016.
extracting the size and moving patterns of individuals passing.
detects 89% of the number of people passing. PIR sensors
By means of motion histograms based on frame-differenced
provide an alternative to IR sensor arrays, however the cost and
images, the histograms classify detected movements.
effort of employing multiple sensor nodes for each entry/exit
Probabilistic correlation is applied to determine a people count.
point is a cost-side disadvantage. The goal of this thesis is to
The results of multiple cameras are joined in order to form a
develop a system based on just one PIR sensor and one sensor
movement vector for each individual recognized. In contrast,
node per each observed entry/exit point. Sensor Fusion Results
proposes a solution based on a single ceiling-mounted camera,
of a building occupancy estimation system applying different
which identifies people by background extraction of the camera
types of sensors is found in [6]. The system consists of camera,
image. A non-background “blob” is recognized, and its size is
CO2 and PIR sensors. It uses a Hidden Markovian Model
estimated and compared to previously established bounds of
(HMM) based on an Extended Kalman Filter (EKF) in order to
people’s pixel dimensions. A people count is derived from the
derive building occupancy. The approach integrates historical
results of this analysis. The system reaches a claimed accuracy
data and current sensor readings to estimate the true state of the
of 98.5%. The major disadvantage of a camera-based system is
system, adjusting for sensor noise (false observations) and
that it requires an ambient light source and relatively powerful
stochastic processes, e.g. uncertain people movement patterns.
computer resources to perform image processing.
III. SYSTEM ARCHITECTURE
C Ultrasonic Sensors
The authors of introduce a system employing ultrasonic
In this project, to count the number of people entering from
sensors. Per each observed area a three-node sensor cluster is
the door, Raspberry Pi board has been used.Which is a SBC,
established, whereby each sensor node mounts an ultrasonic
on which we interfaced a Picamera. Picamera is used for
sensor. Multiple clusters are joined to cover a wider area.
capturing the images of the people. The Raspberry Pi board is
Nodes in each cluster communicate sensor readings by an RF
connected to the monitor (Display) through HDMI port, for
link to the cluster’s coordinator node. The latter contributes its
getting the results. The monitor shows the number of people
own sensor measurements. By means of a distributed
captured by Picamera.The number of face detected is displayed
algorithm, nodes decide on whether to count a detected person.
on the counter. OpenCV is a library which is used for
The sensor nodes require clock synchronization at the
interfacing the camera to the board.
millisecond level in order to correlate the data exchanged.
Despite the availability of clock synchronization protocols this
imposes a disadvantage to this approach. The system achieves
an overall counting accuracy of 90% using a probabilistic
estimate of the total count, despite individual clusters achieving
only around 50-70% accuracy.
D Infrared Sensor
IR arrays combine a matrix of IR sensors to form array
detectors. As the name suggests the sensor signals are provided
as a matrix, where each element of the matrix corresponds to
one IR sensor. Pattern recognition algorithms are able to detect
people moving across the sensor’s view at a claimed accuracy
of 95%. This holds true even if two pedestrian’s paths cross, or
people walk in parallel. IR arrays provide a cost-effective
solution and also operate without any ambient light source. IR
arrays are widely used in commercial systems.
E Infrared Motion Sensors
In people counting system based on PIR motion detectors ,for
each passage monitored, three PIR sensors are installed at a
distance of 0.8m. The sensors are connected to a coordinator
by a wireless RF link. Sensors detect motion events and send
these data to the coordinator. The coordinator infers a people
count from correlating the number, phase and time difference
of peaks found in the signal. The system achieves a rate of
100% to detect the direction of movement, and accurately
IJREAMV02I01894
www.ijream.org
Fig: 1.1 Block diagram of People Counting System
A Block Diagram Description
a Raspberry Pi Board
The Raspberry Pi Camera Board is a custom designed add-on
module for Raspberry Pi hardware. It attaches to Raspberry Pi
hardware through a custom CSI interface. The sensor has 5
megapixel native resolution in still capture mode. In video
mode it supports capture resolutions up to 1080p at 30 frames
per second. The camera module is light weight and small
making it an ideal choice for mobile projects.
© 2016, IJREAM All Rights Reserved.
International Journal for Research in Engineering Application & Management (IJREAM)
ISSN : 2494-9150 Vol-02, Issue 01, APR 2016.
In this example you will learn how to create a camera
IV. ALGORITHM
board object to connect to the Raspberry Pi Camera Board,
capture images from the camera and process them in Python
1. Start
programming.
2. Initialize the raspberry Pi board.
3. Assign memory using stream.
Raspberry Pi Model B has 512Mb RAM, 2 USB ports and an
4. Check for option 1 or option 2.
Ethernet port. It has a Broadcom BCM2835 system on a chip
5. If option = 1 (which is video)
which includes an ARM1176JZF-S 700 MHz processor, Video
i. Set the resolution of Picamera
Core IV GPU, and an SD card. It has a fast 3D core accessed
ii. Capture image from camera.
using the supplied OpenGL ES2.0 and OpenVG libraries. The
iii. Create OpenCV image.
chip specifically provides HDMI and there is no VGA support.
6. If option = 2 ( .jpg file )
The foundation provides Debian and Arch Linux ARM distrii. Read stored .jpg file.
butions and also Python as the main programming language,
7. Load cascade file for detecting faces
with the support for BBC BASIC, C and Perl.
haarcascade_frontalface_alt.xml
8. Convert image from colour to grey scale.
This board is the central module of the whole embedded image
9. Detect faces in the image.
capturing and processing system as given in figure 3.1. Its
10. Before counting faces, generate the reset pulse.
main parts include: main processing chip, memory, power
11. Give pulses to counter to show the number of face
supply HDMI Out, Ethernet port, USB ports and abundant
detected in the image.
global interfaces.
12. Show image on tft screen with rectangle around
every face found.
13. Save the result image.
14. Wait for break key. Break key = ‘q’.
15. Go to start.
V.
3
RESULT ANALYSIS
While designing PCB for relay circuitry, LED and relay were
not working simultaneously. Relays are used as a switch,
which is used to reset and give pulse for counter.
Fig: 1.2 Raspberry Pi Board Model
The Raspberry Pi 2 delivers 6 times the processing capacity of
previous models. This second generation Raspberry Pi has an
upgraded Broadcom BCM2836 processor, which is a powerful
ARM Cortex-A7 based quad-core processor that runs at
900MHz. The board also features an increase in memory
capacity to 1Gbyte.
So the LED was removed and circuitry containing relays,
connectors, resistors, transistors, diodes were designed.
Counter was added so that number of face detected could be
visible in numbers. Regarding program some algorithms were
added, for proper face detection.
Project working snapshot
Step 1
Fig:1.4 Initialization of Raspberry Pi and Counter
Fig:1.3 Circuit diagram of camera interfacing with Raspberry
pi and also HDMI to display.
IJREAMV02I01894
www.ijream.org
In this project counter circuitry has been used for counting the
faces detected by the Picamera and also shows the count of
© 2016, IJREAM All Rights Reserved.
International Journal for Research in Engineering Application & Management (IJREAM) 4
ISSN : 2494-9150 Vol-02, Issue 01, APR 2016.
stored file image. The counter can count upto range 000000 to
Program
999999.
import io
import picamera
Step 2 (Option 1:Capture image from camera )
import cv2
import numpy
#----from PIL import Image
#from scipy.misc import toimage
#from matplotlib import pyplot as plt
# for pulse
import RPi.GPIO as GPIO
import time
GPIO.setwarnings (False)
GPIO.setmode (GPIO.BOARD)
GPIO.setup (11, GPIO.OUT)
#GPIO.output (11, True)
GPIO.output (11, False)
Fig1.5 Face detected by PiCamera and displayed on the screen.
# reset o/p
GPIO.setup (13, GPIO.OUT)
#GPIO.output (13, True)
GPIO.output (13, False)
#----option = 1
while True:
#Create a memory stream so photos doesn't need to be
#capture from picamera
with picamera.PiCamera() as camera:
camera.resolution = (320, 240)
#camera.start_preview ()
camera.capture(stream, format='jpeg')
time.sleep(1)
Fig1.6 The count is displayed on the counter.
#file_ptr = open("/home/pi/Downloads/face_img6.jpg")
Step 3: (Option 2: read stored .jpg file)
#Convert the picture into a numpy array
buff = numpy.fromstring(stream.getvalue(),
cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcas
cade_frontalface_alt.xml')
#Convert to grayscale
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#Look for faces in the image using the loaded cascade
# for pulse
#GPIO.output (11, False)
GPIO.output (11, True)
time.sleep (0.05)
#GPIO.output (11, True)
GPIO.output (11, False)
time.sleep (0.05)
#GPIO.cleanup ()
# show the frame after pulse in option = 1 and option =
Fig 1.7This are used Face detected from stored file.
cv2.imshow("Frame", image)
#Save the result image
cv2.imwrite('result.jpg',image)
# wait for break key
IJREAMV02I01894
www.ijream.org
© 2016, IJREAM All Rights Reserved.
International Journal for Research in Engineering Application & Management (IJREAM)
ISSN : 2494-9150 Vol-02, Issue 01, APR 2016.
key = cv2.waitKey(1) & 0xFF
#print key
# if the 'q' key is pressed, break from the loop
if key == ord("q"):
break
# cleanup the camera and close any open windows
#camera.release()
cv2.destroyAllWindows()
VI. CONCLUSION
This master thesis presents an approach to count people
passing through a virtual gate using a fixed cheap Picamera
mounting vertically on the raspberry Pi board and Python
programming tool linked to the application. The results show
that using a camera to count people is good alternative to other
sensors for big entrance because more accurate. But it shows
also that the system needs a lot of improvements to be really
reliable.
ACKNOWLEDGMENT
It gives us great pleasure in presenting the project report on
‘PEOPLE COUNTING SYSTEM USING RASPBERRY PI
WITH OPENCV’. We would like to take this opportunity to
thank my internal guide Prof. A.D. Tupkar for giving me all the
help and guidance We needed. We are really grateful to them
for their kind support. Their valuable suggestions were very
helpful.
REFERENCES
[1] K. Terada, D. Yoshida, S. Oe, and J. Yamaguchi, A method of
counting the passing people by using the stereo images, International
conference on image processing, 0-7803-5467-2,1999
[2] Haritaoglu and M. Flickner, Detection and tracking of shopping
groups in stores, Proceedings of the 2001 IEEE Computer Society
Conference on Computer Vision and Pattern Recognition , 0-76951272-0,2001.
[3] Gary Conrad and Richard Johnsonbaugh, A real-time people
counter, Proceedings of the 1994 ACM symposium on Applied
computing, 0-89791-647-6 ,1994[ROS94] : M. Rossi and A. Bozzoli,
Tracking and Counting Moving People, IEEE Proc. of Int. Conf.
Image Processing, ,1994.
IJREAMV02I01894
www.ijream.org
© 2016, IJREAM All Rights Reserved.
5
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising