Skip to main content

People counter

People counter is a microservice that takes a URL with image in JPG or PNG format and returns the number of people in the image. This service can be used to process images from a web cam to monitor waiting lines or occupancy of a room. To use the service in a real invironment you need to setup a web cam that can expose a PNG or JPG image as a URL. A standard importer can the be used to call the counting service with this URL as described below. The counted number of people can be used to analyze trends over time or to trigger a notification if an area becomes too crowded.

Example image from ShanghaiTech dataset with estimated count of 117 people.

Example image from ShanghaiTech dataset with estimated count of 682 people.

Installation

The technology used is based on Convolutional Neural Network as described in this paper. The network has been trained on 1198 images with 330.000 heads. The microservice is implemented with PyTorch as described in this GitHub page and takes advantage of GPU accelleration if Cuda is installed on the server.

helm install count 3d-t/count

Since the microservice is quite large it make take several minutes to install. You can check the status of the installation and deployment with the kubernetes command line tools.

Testing

To test the service enter open a web browser or use curl to send a test request:

curl http://count.localhost/test

This converts a test image on the server and should provide the following response:

{'count': 870}

To convert a real image find an image on the internet by searching for crowd and enter the URL of the image as a query parameter.

curl http://count.localhost/?url=https://www.agnarchy.com/wp-content/uploads/2015/01/vail.jpeg

Importer

You can now automatically import the number of people from a web image with an importer that runs every hour. The data field includes the topic and the url where the image is stored. You can replace this with the location of your web cam image. The topic station.people.count is set by sending an http get request to the count service for a URL defined in the data section. The count field of the json response is set to the value of the topic.

name: 'Crowd counter'
cron: '0 0 * * * *'
data: `
topic, url
stadion.people, https://cdn.wallpapersafari.com/58/93/G5gkKT.jpg
`
mappings:
- key: count
formula: 'http.get(''http://count.localhost/?url='' + url).count'