Skip to main content

An advanced library for crowd detection, tracking, and analysis in videos.

Project description

Crowd Vision: Advanced Crowd Tracking & Analysis 🚶‍♂️🚶‍♀️ crowd_vision is a high-performance Python library for detecting, tracking, and analyzing crowds in video streams. It uses a hybrid tracking approach with Kalman filters and appearance features to maintain stable object IDs even in dense and complex scenes.

The entire pipeline is wrapped in a simple-to-use API, allowing you to get detailed crowd analytics from a video file with just a few lines of code.

✨ Features Robust Person Detection: Utilizes a pre-trained Faster R-CNN model from torchvision for accurate person detection.

Hybrid Tracking Algorithm: Combines IOU (Intersection over Union) and appearance-based matching (color histograms) for reliable tracking that resists ID switches.

Kalman Filter Motion Prediction: Predicts object motion to handle temporary occlusions and maintain consistent tracks.

Motion-Aware Crowd Clustering: Uses the DBSCAN algorithm on both spatial and velocity features to intelligently identify and group individuals into crowds.

Easy-to-Use API: Process an entire video and get detailed crowd analytics with a single function call.

Detailed Output: Generates an annotated output video and a CSV log file with frame-by-frame data on crowd size and composition.

⚙️ Installation Installation is a two-step process. For the best results, it's highly recommended to install the core deep learning and computer vision libraries first, as pip can sometimes struggle with their complex dependencies.

Step 1: Install Core Dependencies (Recommended)

Follow the official instructions for your specific system (e.g., with or without a CUDA-enabled GPU).

PyTorch: Go to the PyTorch Official Website and select the correct options for your OS and package manager. This will give you the correct command to run.

OpenCV: pip install opencv-python

Step 2: Install crowd_vision

Once the core libraries are installed, you can install the package directly from PyPI:

pip install crowd_vision

🚀 How to Use Using the library is designed to be straightforward. You provide a path to a video file and an output directory, and the analyze_video function handles the entire pipeline.

from crowd_vision import analyze_video import os

1. Define the path to your video and where to save the results

video_input_path = "path/to/your/video.mp4" output_directory = "results/run_01"

2. Create the output directory if it doesn't exist

os.makedirs(output_directory, exist_ok=True)

3. Check if the video file exists before running

if os.path.exists(video_input_path): print(f"Starting analysis for: {video_input_path}")

# 4. Run the full analysis pipeline
# You can customize many parameters here (see below)
analyze_video(
    video_path=video_input_path,
    output_dir=output_directory,
    confidence_threshold=0.5,
    motion_weight=0.2,
    app_weight=0.5
)
print(f"✅ Analysis complete! Results saved in '{output_directory}'")

else: print(f"❌ Error: Video not found at '{video_input_path}'")

Customization You can tweak the tracker's behavior by passing optional arguments to analyze_video:

confidence_threshold: The minimum score for a person detection to be considered (e.g., 0.5).

tracking_max_age: How many frames a track can be lost before it's deleted (e.g., 30).

motion_weight: How much velocity matters when clustering people into groups (e.g., 0.2).

app_weight: The balance between IOU and appearance for matching tracks (e.g., 0.5).

📊 Output The analyze_video function will generate two files in your specified output directory:

crowd_analysis_output.mp4: The original video, annotated with:

Bounding boxes and unique IDs for each tracked person.

A colored convex hull drawn around identified crowds.

Text indicating the number of people in each crowd.

crowd_analysis_data.csv: A CSV file containing a frame-by-frame log of all detected crowds, with the following columns:

Frame

Time_Seconds

Crowd_ID

Person_Count

Track_IDs (a semicolon-separated list of the IDs of people in the crowd)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crowd_vision-0.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crowd_vision-0.1.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file crowd_vision-0.1.0.tar.gz.

File metadata

  • Download URL: crowd_vision-0.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for crowd_vision-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa1958e4726cdf0535b7f1ada0aed7afd4a65568efb8a0ee802d4bd45eaf79d6
MD5 6855d0f234b4c979a23cfe28b8979a03
BLAKE2b-256 a63c639daf7ce42b380525730ff618e9d67ae28a490838b45fb745a3d7b40dd3

See more details on using hashes here.

File details

Details for the file crowd_vision-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: crowd_vision-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.1

File hashes

Hashes for crowd_vision-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6cd2f2bccdf023e9dcbc427a2260d50a910021ea4796a89c23463490272d0323
MD5 a7415cf93302c2d1206c6f232fe24e6a
BLAKE2b-256 96a18ce8f7cf7af75956c1254e642d3237ff1ecfc8025e369e05a7031f8806c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page