Skip to content

2acholsk1/pedestrian_tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PEDESTRIAN TRACKER

Table of Contents

Main goal

A pedestrian tracking system using probabilistic graph models to assign bounding rectangles (Bounding Boxes) to people in consecutive video frames

Installation

Clone repository:

git clone https://github.com/2acholsk1/pedestrian_tracker.git
cd pedestrian_tracker

After clone repository, you need to setup virtual environemnt, with which commands in the Makefile will help:

make setup-venv

Remember to activate venv with command: source bin/activate.

Then, you can easily build and install package by using:

make setup

If you want to use example data unzip it in data folder:

unzip c6s1

Usage

To start the program type, remeber to add path which contain frames of video to analyze:

python3 src/__main__.py path/to/frames/folder

If you want to ocheck accuracy, remember to add path to file with correct answers:

python3 src/result_accuracy.py path/to/file

Results

Overall accuracy for c6s1 data folder is 95%, 2585 correct answers out of 2733 total. pedestrians gif

Documentation

The project consists of two main classes BoundBox and Histogram.

BoundBox class manages rectangular regions (bounding boxes) on images. Methods:

  • init(self, coordinates: list, image: cv2.Mat): Initializes with bounding box coordinates and an image.
  • compute_coords(self, coordinates: list): Converts and stores coordinates.
  • compute_bb(self): Computes and extracts bounding boxes from the image.
  • return_bb(self) -> list: Returns the list of bounding boxes.
  • return_nodes(self) -> list: Returns the list of node identifiers.

Histogram class computes and compares histograms of bounding boxes. Methods:

  • init(self, bb: list, new_obj_prob: float, factor_graph: DiscreteFactor): Initializes with bounding boxes, new object probability, and a factor graph.
  • hist_bb_calc(self) -> list: Computes histograms for each bounding box.
  • hist_bb_compare(self, bb_current_hist: list, bb_previous_hist: list) -> DiscreteFactor: Compares histograms between frames and updates the factor graph.

There is also an auxiliary class - Visualize, which, as the name suggest, is used to visualize effects of the project.

Main function processes the images and bounding boxes, computes histograms, compares them, and performs belief propagation to track or identify objects across frames.

Below is a diagram describing how to build a graph with two images and their bounding boxes: example_process

Code workflow

drawio

  1. Initialization:
  • Initialize variables for current and previous histograms (hist_curr, hist_prev), current bounding boxes (bb_curr), and a flag (bb_none) to handle cases with no bounding boxes.
  • Set a probability for new objects (prob_new).
  • Prepare a list to store results.
  1. Iterate Over Images:
  • Loop through each image in the provided image paths.
  • For each image, read and discard the first line (usually the image filename).
  1. Read Bounding Box Information:
  • Read the number of bounding boxes (bb_num) for the current image.
  • If no bounding boxes are present (bb_num is "0"), set the bb_none flag and skip further processing for the current image.
  1. Compute Bounding Boxes:
  • If bounding boxes are present, create an instance of BoundBox with the coordinates and image.
  • Call compute_bb method to extract bounding boxes.
  • Retrieve the bounding boxes (bb_curr) and node identifiers (nodes).
  • Add nodes to the factor graph.
  1. Compute Histograms:
  • Create an instance of Histogram with the current bounding boxes, new object probability, and factor graph.
  • Call hist_bb_calc method to compute histograms for the current bounding boxes.
  1. Handle No Bounding Boxes in Previous Image:
  • If bb_none flag is set (no bounding boxes in the previous image), reset the flag, append -1 results for the current image, and skip further processing.
  1. Setup Node Possibility Matrix:
  • Create a matrix to represent the possibilities of node connections.
  • Initialize the matrix with ones and set diagonal elements to zero (to prevent self-connections).
  1. Compare Histograms and Update Factor Graph:
  • If previous histograms are available, call hist_bb_compare method to compare current and previous histograms, and update the factor graph.
  • Use combinations of current and previous histogram indices to create and add factors to the factor graph.
  • Add edges to the factor graph based on histogram comparisons.
  1. Perform Belief Propagation:
  • Create an instance of BeliefPropagation with the factor graph.
  • Calibrate the factor graph using the calibrate method.
  • Query the factor graph to determine the most probable states of the variables (bounding boxes).
  • Store and print the results, adjusting the indices as needed.
  1. Handle No Previous Histograms:
  • If no previous histograms are available, append -1 results for the current image.
  1. Write Results to File:
  • After processing all images, write the results to a text file (data/check/results.txt).

Bugs & Feature Requests

Please report bugs and request features using the Issue Tracker.

About

A pedestrian tracking system using probabilistic graph models to assign bounding rectangles (Bounding Boxes) to people in consecutive video frames

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors