Topvennie / Online-Crowd-Analyzer

Use object detection to count the amount of people passing by a certain point
MIT License
0 stars 0 forks source link

Online-Crowd-Analyzer

This repository allows for analyzing footage to detect how many people have passed. It does this dans, tracking them and keeping count of the amount that have passed a predefined line. The data is saved in a database and make accessible by a webserver.

It supports multiple detectors and trackers and can be easily extended with new ones. See the README.md in the detector and tracker folders for more information on how to use them.

pyproject.toml only holds the dependencies required to run the project without any detectors or trackers. Some detectors and trackers have additional dependencies, usually they will download them automatically. Afterwards you might have to restart the project. However some require manual installation, for more information see the README.md in the detector and tracker folders.

Prerequisites

For ubuntu:

sudo apt update; sudo apt install build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev curl git \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev \
libev-dev ffmpeg libsm6 libxext6

How to run

  1. Install dependencies poetry install
  2. Configure the project in config.yaml
  3. Start the project python src/main.py

Development

Pre-commit hooks are used to ensure code quality. Install the required dependency with poetry install --with dev. Then run pre-commit install to install the hooks.

Endpoints

The webserver has multiple endpoints that can be used to interact with the project.

Configuration

The configuration file is located in config.yaml. An example configuration file is provided in config.example.yaml. The values used in the example are not necessarily the best values, they are just examples. It is divided into multiple sections, each section is explained below.

1. General

Key Type Default Description
name string None Name of the project. Is used by the database.
port int 5000 Port that the webserver will run on.
logging string INFO The logging level. Can be one of DEBUG, INFO, WARN, ERROR, CRITICAL.
database mapping None The database configuration.
show mapping None The show configuration.
increment list [] List of increment configurations.
decrement list [] List of decrement configurations.

1.1 Database

The database configuration is used to configure the database.

Key Type Default Description
name string None Name of the database.
reset bool False Resets the database on startup. Previous entries are not removed but are marked as invalid.

1.2 Show

The show configuration is used to configure the video feed that is shown. This is only for debugging purposes.

When show is enabled a new window will open showing the video feed. Blue boxes represent detected people. Once they are tracked they have a dot in their center with an ID. If the ID is red, the person is not counted yet. If the ID is green, the person is counted.

Key Type Default Description
enabled bool False Whether to show the video feed.
wait int 1 The amount of ms to wait between frames. Can be used to slow down the video feed. Is ignored if enabled is false.

1.3 Increment / Decrement

Both the increment and decrement sections have the same structure. They are used to define video streams that should be analyzed. Ones that are defined in the increment section will increment the counter when a person is detected. Ones that are defined in the decrement section will decrement the counter when a person is detected.

Key Type Default Description
name string None Name of the stream. Is used by the database to identify entries.
input mapping None Input file or stream configuration.
output mapping None Output file or stream configuration.
detector mapping None Detector configuration.
tracker mapping None Tracker configuration.
1.3.1 Input
Key Type Default Description
file string None Path to the file. Can be a video file or a stream.
counting_line int None Y value of the counting line. The counting line is a horizontal line that is used to determine if a person has passed.
1.3.2 Output
Key Type Default Description
enable bool False Whether to save the output to a file. This will slow down the processing.
type string "images" Type of output. Can be either "video" or "images"
file string "" Path to the file. Only used if type is set to "video". Is ignored if enable is false or type is set to images
frame_mod int 100 Number to mod the frame by. This is used to determine if a frame should be saved. A value of 1 means that every frame is saved. Only relevant if type is "images"
1.3.3 Detector
Key Type Default Description
model string None Desired model type. See the detector's README.md for more information.
arguments mapping {} Arguments that are passed to the detector. See the detector's README.md for more information.
frame_mod int 1 Number to mod the frame by. This is used to skip frames. A value of 1 means that every frame is processed.
1.3.4 Tracker
Key Type Default Description
model string None Desired model type. See the tracker's README.md for more information.
arguments mapping {} Arguments that are passed to the tracker. See the tracker's README.md for more information.