In response to social distancing measures during COVID-19 pandemic, it has been imposed to limit the number of people in almost every location and educational institutions are not exempted to it. Hence the idea of counting the actual number of people inside the building became a requirement.
On each of library entrances (where I currently work), there are counters at the gate that logs each entries and exits. From these logs, reports are generated on a regular basis (monthly). However, this solution does not provide a live counter that can be viewed and monitored on a near real-time basis.
Despite of having a simple requirement, I realized that none of the vendors we have can provide exactly what need. Not to mention the very high cost that comes with the partial solution they offer.
We decided to create our own solution. After checking our gate counters, we found a feature that we can use to send the current count to a server via HTTP, however is it not being utilized. We played around the newly found feature/setting and set it to send update every 10000 millisecond to emulate near real-time couting.
Re-configurations are made to the entrances’ people counters to send update to a server every few seconds. From the server, the information is parsed, and calculations are made for the occupancy count. The information is then displayed in a browser that refreshes every few seconds as shown below:
Fig 1: Used at entrance display
Fig 2: Backend Display (More details)
Historical data are then saved on a Database and then displayed using Dash by Plotly module. Using heatmap chart on a daily and hourly basis we're be able to see the occupancy trends across several days.
-
Clone this repository
$ git clone https://github.com/RonBulaon/PeopleCounter.git
-
Replace / Update the folloeing to match your environment.
- Update the on files at public/*.html files
- Sensor IP addresses, Schedule, Database name and Database credentials at config.conf
- If you want teams notification update [msteams] section at config.conf
- Update script /path/to/folder/ at checker.py and stopDashboard.py
- Update <local_IP> and <remote_IP> IPs at forwarder.py
-
Go to the downloaded repository's source folder and install the requirements.
$ cd PeopleCounter $ pip install -r Requirements.txt
-
Execute script this way:
$ python3 checker.py $ python3 stopDashboard.py
Note :
- checker.py and stopDashboard.py would start/restart the all running scripts every execution.
- The these scripts can be used with cron to regularly check or restart the scripts if needed.
- YOu must move it to PeopleCounter directory to make it work properly.
-
Run forwarder.py this will receive the count from sensors then forward it to port 8080 of the script above. This can be executed from same server or from remote device as gateway/forwarder. Just make sure that you have indicated the proper ports and IP addresses for remote and local.
$ python3 forwarder.py
-
From your favorite browser open the following for backend (Fig 2, Fig 3):
- https://<domain.com>/dashboard/
- https://<domain.com>/public/kgc_detailed.html
- https://<domain.com>/public/lks_detailed.html
While these on your gate display (Fig 1):
- https://<domain.com>/public/lks.html
- https://<domain.com>/public/kgc.html
I placed the browser on auto run with the following configuration:
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" https://<domain.com>/public/lks.html --start-fullscreen
or this if you want it on a 2nd monitor:
"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" https://<domain.com>/public/lks.html --window-position=1925,500 --start-fullscreen
I'm using Edge Chromium but this will also work with Google Chrome.
The device we have is Brickstreamm 2300. It has a setting called Real Time Data Streaming, here's what I did:
- I have set all our sensors to send realtime data to the IP address of where I have forwarder.py running.
- The data will be sent evey 10000 millisecond in xml format, which also means forwarder.py expects an xml data.
- The counter counts continuously and will always send the total number of entry and exit from the day it was installed. This will be parsed to check the difference between milliseconds resulting the entry and exit counts for that time.
- If you are using a different device you should change how I parse the received data at forwader.py lines 56 to 78.
- Ubuntu on Azure
- Nginx as reverse proxy
- HTTPS setup through Let's Encrypt