https://github.com/lamaabdeldayem/color-detection
A Python project for detecting a yellow object (e.g., a ball) in a video using OpenCV and PIL, applying color-based masking and drawing bounding boxes around the detected object.
https://github.com/lamaabdeldayem/color-detection
color-detection computer-vision hsv-colorspace object-tracking opencv pil python video-processing
Last synced: 2 months ago
JSON representation
A Python project for detecting a yellow object (e.g., a ball) in a video using OpenCV and PIL, applying color-based masking and drawing bounding boxes around the detected object.
- Host: GitHub
- URL: https://github.com/lamaabdeldayem/color-detection
- Owner: lamaabdeldayem
- Created: 2024-09-17T11:34:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-17T13:15:22.000Z (over 1 year ago)
- Last Synced: 2025-03-27T13:49:28.467Z (over 1 year ago)
- Topics: color-detection, computer-vision, hsv-colorspace, object-tracking, opencv, pil, python, video-processing
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Video Processing Project with OpenCV and PIL π₯β½
This project demonstrates the detection of a yellow ball in a video using **OpenCV** and **PIL**. The code applies color-based masking and identifies the bounding box of the detected object, then draws the bounding box around the object in the video frames.
## Requirements π¦
To run the project, you need to install the required dependencies using `pip`:
- `opencv-python`
- `Pillow`
- `numpy`
### Installation π§
1. Clone the repository:
```bash
git clone https://github.com/lamaabdeldayem/Color-Detection.git
cd Color-Detection
```
2. Install the dependencies:
```bash
pip install opencv-python Pillow numpy
```
## Usage π
Make sure the video file `Bouncing Red Ball (1).mp4` is in the same directory as the script, or update the path in the script accordingly.
Run the script:
```bash
python script_name.py
```
### Description of the Code π
- The script loads a video (`Bouncing Red Ball (1).mp4`) using OpenCV.
- It converts each frame from the video to the **HSV color space**.
- It defines a color range for yellow in the HSV space and creates a **mask** for pixels within this range.
- The script finds the bounding box of the yellow object in the mask and draws a rectangle around it on the original frame.
- The video is displayed with the bounding box, and you can press `q` to quit the video.
### Example π¬
The video will show the bounding box drawn around the yellow object as it moves through the frames.
### Customizing the Color π
If you want to track a different color, you can modify the `yellow` variable with a new color in the BGR color space. The `get_limits` function will automatically adjust the HSV range for the new color.
```python
yellow = [0, 0, 255] # Change to a new BGR color if needed
```
### Example of `get_limits`:
If you have your custom function `get_limits` to return the lower and upper limits for HSV color detection, ensure itβs implemented in the `util.py` file as shown in the code.
```python
# Example get_limits function
def get_limits(color):
# Your implementation of HSV limits based on the input color
pass
```
---