People Counting in Real-Time with an IP camera.
People Counting in Real-Time using live video stream/IP camera in OpenCV.
NOTE: This is an improvement/modification to https://www.pyimagesearch.com/2018/08/13/opencv-people-counter/
Live demo
Single Shot Detector
with a MobileNet architecture. In general, it only takes a single shot to detect whatever is in an image. That is, one for generating region proposals, one for detecting the object of each proposal.MobileNet
, as the name implies, is a DNN designed to run on resource constrained devices. For e.g., mobiles, ip cameras, scanners etc.centroid
of the bounding boxes.(x, y)
co-ordinates of the objects in an image.unique ID
is assigned to every particular object deteced, for tracking over the sequence of frames.First up, install all the required Python dependencies by running: pip install -r requirements.txt
NOTE: Supported Python version is 3.11.3 (there can always be version conflicts between the dependencies, OS, hardware etc.).
To run inference on a test video file, head into the root directory and run the command:
python people_counter.py --prototxt detector/MobileNetSSD_deploy.prototxt --model detector/MobileNetSSD_deploy.caffemodel --input utils/data/tests/test_1.mp4
To run on a webcam, set "url": 0
in utils/config.json
and run the command:
python people_counter.py --prototxt detector/MobileNetSSD_deploy.prototxt --model detector/MobileNetSSD_deploy.caffemodel
To run on an IP camera, setup your camera url in utils/config.json
, e.g., "url": 'http://191.138.0.100:8040/video'
.
Then run the command:
python people_counter.py --prototxt detector/MobileNetSSD_deploy.prototxt --model detector/MobileNetSSD_deploy.caffemodel
The following features can be easily enabled/disabled in utils/config.json
:
{
"Email_Send": "",
"Email_Receive": "",
"Email_Password": "",
"url": "",
"ALERT": false,
"Threshold": 10,
"Thread": false,
"Log": false,
"Scheduler": false,
"Timer": false
}
If selected, we send an email alert in real-time. Example use case: If the total number of people (say 10 or 30) are exceeded in a store/building, we simply alert the staff.
"Threshold": 10
.1. Setup your emails:
In the config, setup your sender email "Email_Send": ""
to send the alerts and your receiver email "Email_Receive": ""
to receive the alerts.
2. Setup your password:
Similarly, setup the sender email password "Email_Password": ""
.
Note that the password varies if you have secured 2 step verification turned on, so refer the links below and create an application specific password:
utils/thread.py
. If you ever see a lag/delay in your real-time stream, consider using it.OpenCV's internal buffer
(which basically stores the new frames yet to be processed until your system processes the old frames) and thus reduces the lag/increases fps."Thread": true,
in config.# runs at every day (09:00 am)
schedule.every().day.at("9:00").do(run)
# automatic timer to stop the live stream (set to 8 hours/28800s)
end_time = time.time()
num_seconds = (end_time - start_time)
if num_seconds > 28800:
break
Main:
Optional:
saimj7/ 19-08-2020 - © Sai_Mj.