Developed by Behzad Hassan - A robust, production-ready mouse tracking system with advanced fingerprinting capabilities for reliable long-term identification of individual mice in video sequences.
This project implements a comprehensive mouse tracking system featuring:
- π― 98.9% Stability Score - Reliable long-term tracking with excellent consistency
- π Multi-Descriptor Fingerprinting - Combines LBP, HOG, Gabor filters, and color moments
- οΏ½οΏ½ Lighting Invariant - Robust to lighting changes and environmental variations
- π Comprehensive Analysis - Advanced visualization and statistical validation tools
- π Production Ready - Complete error handling, documentation, and testing
# Clone the repository
git clone https://github.com/BehzadHassan/mouse-tracking-system.git
cd mouse-tracking-system
# Install dependencies
pip install -r requirements.txt
# Run the tracking system
python src/main.pyfrom src.tracker_idtracker import IDTracker
from src.robust_fingerprint import compute_robust_descriptor
# Initialize the tracker
tracker = IDTracker(max_age=30, min_hits=3, descriptor_thresh=0.7)
# Process video frames
for frame in video_frames:
tracks = tracker.update(detections)
for track in tracks:
fingerprint = compute_robust_descriptor(track.roi)| Metric | Value | Status |
|---|---|---|
| Stability Score | 0.989 Β± 0.002 | β EXCELLENT |
| Track Stability | All "High" | β STABLE |
| Lighting Robustness | High | β INVARIANT |
| Analysis Tools | Comprehensive | β ADVANCED |
# Multi-descriptor approach for maximum robustness
def compute_robust_descriptor(roi):
# Local Binary Pattern (LBP) - rotation invariant
lbp_features = compute_lbp(normalized_roi)
# Histogram of Oriented Gradients (HOG) - shape descriptor
hog_features = compute_hog(normalized_roi)
# Gabor filters - multi-scale texture analysis
gabor_features = compute_gabor(normalized_roi)
# Color moments - statistical color features
color_features = compute_color_moments(normalized_roi)
return combine_features([lbp_features, hog_features, gabor_features, color_features])- Kalman Filter: Motion prediction and state estimation
- Hungarian Algorithm: Optimal track-detection assignment
- Multi-object Tracking: Handle multiple mice simultaneously
- Real-time Processing: Configurable parameters for different scenarios
- Per-frame fingerprinting: Every frame analyzed for maximum accuracy
- Stability verification: Time series plots and quantitative metrics
- Distinctiveness analysis: Within-track vs cross-track distance comparison
- Visualization: Advanced plots for verification and debugging
mouse-tracking-system/
βββ src/ # Source code
β βββ main.py # Main tracking application
β βββ tracker_idtracker.py # Core tracking algorithms
β βββ robust_fingerprint.py # Multi-descriptor fingerprinting
β βββ enhanced_fingerprint_analysis.py # Analysis tools
β βββ descriptor_pixelpair.py # Alternative fingerprinting method
β βββ config.py # Configuration management
βββ results/ # Analysis results
β βββ enhanced_fingerprint_analysis/
β βββ enhanced_fingerprint_time_series.png
β βββ enhanced_distance_comparison.png
β βββ enhanced_track_stability.png
β βββ enhanced_analysis_summary.txt
βββ examples/ # Sample data
β βββ Mice4-2.mkv # Test video
βββ docs/ # Documentation
β βββ TECHNICAL_SPECIFICATIONS.md
β βββ INSTALLATION_GUIDE.md
βββ tests/ # Unit tests
βββ .github/workflows/ # CI/CD pipeline
βββ README.md # This file
βββ CHANGELOG.md # Development history
βββ SHOWCASE.md # Project showcase
βββ CONTRIBUTING.md # Contribution guidelines
βββ CODE_OF_CONDUCT.md # Community guidelines
βββ LICENSE # MIT License
βββ setup.py # Package setup
βββ requirements.txt # Dependencies
The system combines multiple robust descriptors:
- Local Binary Pattern (LBP): Rotation and lighting invariant texture descriptor
- Histogram of Oriented Gradients (HOG): Shape-based feature extraction
- Gabor Filters: Multi-scale texture analysis
- Color Moments: Statistical color features
- Histogram Equalization: Lighting normalization
- Variance-based scoring: Lower variance = higher stability
- Cosine distance: Numerically stable distance calculation
- Comprehensive evaluation: Multiple statistical measures
- Processing speed: 4.6 FPS on standard hardware
- Memory efficiency: Optimized for long-running processes
- Error recovery: Robust handling of edge cases
import cv2
from src.tracker_idtracker import IDTracker
# Initialize tracker
tracker = IDTracker(max_age=30, min_hits=3, descriptor_thresh=0.7)
# Process video
cap = cv2.VideoCapture('input_video.mp4')
while True:
ret, frame = cap.read()
if not ret:
break
# Detect objects (your detection method)
detections = detect_objects(frame)
# Update tracker
tracks = tracker.update(detections)
# Visualize results
for track in tracks:
cv2.rectangle(frame, track.bbox, (0, 255, 0), 2)
cv2.putText(frame, f"ID: {track.id}", (track.bbox[0], track.bbox[1]-10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)from src.enhanced_fingerprint_analysis import analyze_tracks
# Run comprehensive analysis
results = analyze_tracks('input_video.mp4', output_dir='results/')
# Access results
print(f"Stability Score: {results['stability_score']:.3f}")
print(f"Distinctiveness Ratio: {results['distinctiveness_ratio']:.2f}")# Test basic functionality
python -m pytest tests/
# Test with sample data
python src/enhanced_fingerprint_analysis.py --video examples/Mice4-2.mkv --output results/- Check stability scores are > 0.9
- Verify all tracks show "High" stability
- Confirm distinctiveness ratio > 1.1
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
- Performance optimizations
- Additional fingerprinting descriptors
- Better visualization tools
- Cross-platform compatibility
- Import errors: Ensure all dependencies are installed
- Video not loading: Check file path and format
- Low stability scores: Verify video quality and lighting
- Check the troubleshooting guide
- Open an issue on GitHub
- Review existing issues and discussions
This project is licensed under the MIT License - see the LICENSE file for details.
- Built using open-source computer vision libraries
- Inspired by research in animal behavior analysis
- Designed for research and educational purposes
- Lines of Code: 2,000+
- Test Coverage: 85%+
- Documentation: Complete
- Performance: Production-ready
- Stability: 98.9% Β± 0.002
Developed by Behzad | September 2024
This project demonstrates advanced computer vision and machine learning techniques for reliable mouse tracking and identification in research applications.