This project performs video segmentation using the SAM model and Supervision library. It processes video frames, detects objects, and annotates them with bounding boxes and masks.
- Python 3.x
- PyTorch
- OpenCV
- NumPy
- Supervision
- Ultralytics
- tqdm
-
Clone the repository:
git clone https://github.com/your-repo/video-segmentation.git cd video-segmentation
-
Install the required packages:
pip install torch opencv-python numpy supervision ultralytics tqdm
-
Ensure you have a video file in the same directory as
main.py
. The video file should be in.mp4
format. -
Place your SAM model file (
.pt
format) in the same directory asmain.py
. -
Run the script:
python main.py
main.py
: The main script that loads the video, processes each frame, and performs segmentation using the SAM model.
detect_gpu()
: Checks if a GPU is available and returns the device name.click_event(event, x, y, flags, param)
: Handles mouse click events to select points on the video frames.
- Detects if a GPU is available using
detect_gpu()
. - Loads the SAM model.
- Reads the video file and initializes annotators.
- Processes each frame of the video:
- If a point is selected, it uses the SAM model to generate segmentation masks.
- Annotates the frame with bounding boxes and masks.
- Displays the annotated frame.
- Exits the loop if the 'q' key is pressed.
The .gitignore
file is configured to ignore video files (*.mp4
) and model files (*.pt
).
This project is licensed under the MIT License. See the LICENSE file for details.