This repository contains two Python scripts that leverage YOLOv8 for video-based object detection. The scripts allow you to perform inference either in real-time using a webcam or on a pre-recorded video.
- Real-Time Inference: Use the webcam to process live video streams.
- Offline Inference: Analyze and annotate a pre-recorded video file.
- Performance Metrics: Measure and display the inference time and FPS.
- YOLOv8 Integration: Utilize the YOLOv8 model for robust object detection.
Before running the scripts, ensure you have the following dependencies installed:
- Python 3.8 or higher
- OpenCV (
pip install opencv-python
) - Ultralytics YOLO (
pip install ultralytics
)
This script uses the webcam to perform real-time object detection.
How to Run:
python "VIDEO CAP.py"
This script processes a pre-recorded video file and performs object detection on each frame.
How to Run:
- Place your video file in the desired directory.
- Update the
video_path
variable in the script to point to your video file. - Run the script:
python "COMPUTER VISION video.py"
Both scripts require a pre-trained YOLOv8 model. Update the model path in the following line:
model = YOLO("/path/to/your/yolov8-model.pt")
The camera index is set to 0
by default. Modify this line to use a different camera:
cap = cv2.VideoCapture(0)
Replace video_path
with the path to your video file:
video_path = "/path/to/your/video.mp4"
- Annotated frames are displayed in a window named "YOLOv8 Inference".
- Press
q
to exit the program.
- Real-Time Inference:
- Frames are processed and displayed with bounding boxes and labels for detected objects.
- Video Inference:
- Annotated video frames are displayed with detection results.
-
Webcam Issues:
- Ensure no other application is using the webcam.
- Try changing the camera index (
0
,1
, etc.).
-
Video File Not Opening:
- Verify the
video_path
is correct and points to a valid video file.
- Verify the
-
Performance:
- Use a system with a dedicated GPU for faster inference.
- Reduce the video resolution for better FPS.
This project is licensed under the MIT License. See the LICENSE file for details.
- Ultralytics YOLO for the YOLOv8 framework.
- OpenCV for video handling and visualization.
Feel free to open issues or submit pull requests to improve this project!