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.
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
poetry install
config.yaml
python src/main.py
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.
The webserver has multiple endpoints that can be used to interact with the project.
/count/<camera_name>
- Returns the amount of people that passed the line for a given camera.
The response is a JSON object {"increment": amount, "decrement": amount}
./snapshot/<camera_name>
- Returns the latest snapshot of the given camera.
If no camera is given it will return a JSON object {"error": error_message}
If the camera does not save image output then it will return a black image.
Else it will return the latest image, all images have the same size as the input./health
- Returns the health of each counter.
The response is a JSON object {"health": []}
where each entry in the list is a JSON object {"name": name, "detector": alive or dead, "tracker": alive or dead}
.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.
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. |
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. |
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. |
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. |
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. |
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" |
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. |
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. |