This Python script provides advanced object tracking using OpenCV. It supports multiple tracking algorithms, dynamic object reacquisition, and real-time feature comparison. The system allows users to select objects to track with a mouse, supports named tracking, and includes multiple modes for enhanced performance and reliability.
- Instant Mode: Track objects immediately upon selection with a mouse.
- Named Tracking: Assign names to tracked objects for easier identification.
- Feature Comparison Mode: Reacquire lost objects using initial features captured during selection.
- Real-Time Multithreaded Processing: Capture and process frames in real-time for minimal latency.
- Flexible Tracking Algorithms: Choose from multiple tracking algorithms like CSRT, KCF, MIL, and more.
Ensure you have Python 3.6 or newer installed. The script has been tested with Python 3.11.
-
Clone the Repository
git clone https://github.com/small-cactus/objectTrack.git cd objectTrack
-
Set Up a Python Virtual Environment (optional but recommended)
python -m venv venv venv\Scripts\activate # On Windows source venv/bin/activate # On macOS and Linux
-
Install Required Libraries
pip install -r requirements.txt
Libraries to be installed:
opencv-contrib-python==4.10.0.82
Run the script from your command line:
python3 objectTracking.py
- 'i': Toggle named tracking mode.
- 'f': Toggle feature comparison mode.
- 's': Start tracking (in non-instant mode).
- 'ESC': Reset all tracking.
- 'q': Quit the application.
Adjust parameters based on your setup:
- Camera Index: Change
cap = cv2.VideoCapture(0)
if the default camera is not used.0
is the value you should be changing. - Resolution: Set the desired resolution with
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
andcap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
.
This project is licensed under the MIT License - see the LICENSE file for details.