A Python-based Computer Vision project using OpenCV for real-time image and video analysis.
Implements core CV techniques including object detection, image processing, and visual feature extraction.
Overview โข Features โข How It Works โข Installation โข Usage โข Contributing
- Overview
- Features
- How It Works
- Project Structure
- Tech Stack
- Installation
- Usage
- Core Concepts
- Example Output
- Use Cases
- Troubleshooting
- Contributing
- License
Computer-Vision is a Python project built around OpenCV โ one of the most widely used libraries for real-time computer vision. This project demonstrates practical implementations of CV techniques that can be applied to images, video streams, and webcam feeds.
Whether you're a beginner exploring computer vision or a developer building AI-powered visual pipelines, this project provides a clean, modular foundation.
- ๐๏ธ Real-time video/webcam processing via OpenCV
- ๐ฏ Object & face detection using Haar cascades / DNN
- ๐ผ๏ธ Image preprocessing โ grayscale, blur, threshold, edge detection
- ๐ Contour detection & shape analysis
- ๐จ Color space conversions โ BGR, RGB, HSV, Gray
- ๐ฆ Bounding box drawing with labels
- โก Lightweight โ pure Python, single script entry point
Input Source (Image / Video / Webcam)
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OpenCV Pipeline โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ 1. Frame Capture โ โ โ cv2.VideoCapture / imread
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ 2. Preprocessing โ โ โ Resize, Grayscale, Blur,
โ โ โ โ Normalize, Threshold
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ 3. Feature Detection โ โ โ Edge detection (Canny),
โ โ โ โ Contours, Keypoints
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ 4. Object / Face Detection โ โ โ Haar Cascade / DNN Model
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ 5. Annotation & Display โ โ โ Draw bounding boxes,
โ โ โ โ labels, contours
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโ
โ
โผ
Output Window / Saved Image/Video
Computer-Vision/
โ
โโโ ๐ vision1.py # Main computer vision script
โโโ ๐ LICENSE # Apache 2.0
โโโ ๐ README.md # You are here
Note: Input images/video can be placed in the project root or passed as arguments to
vision1.py.
| Library | Purpose |
|---|---|
Python 3.8+ |
Core programming language |
OpenCV (cv2) |
Image & video capture, processing, detection |
NumPy |
Array/matrix operations on pixel data |
Matplotlib (optional) |
Visualization & plotting results |
1. Clone the repository:
git clone https://github.com/eddiebrock911/Computer-Vision.git
cd Computer-Vision2. Create & activate a virtual environment:
# Create
python -m venv venv
# Activate โ Linux/Mac
source venv/bin/activate
# Activate โ Windows
venv\Scripts\activate3. Install dependencies:
pip install opencv-python numpy matplotlibFor headless environments (servers without display):
pip install opencv-python-headless numpyRun the main script:
python vision1.pyCommon OpenCV operations you can extend:
import cv2
import numpy as np
# --- Load an image ---
img = cv2.imread("input.jpg")
# --- Grayscale conversion ---
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# --- Gaussian Blur ---
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
# --- Edge Detection (Canny) ---
edges = cv2.Canny(blurred, threshold1=50, threshold2=150)
# --- Contour Detection ---
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img, contours, -1, (0, 255, 0), 2)
# --- Face Detection (Haar Cascade) ---
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
# --- Display ---
cv2.imshow("Result", img)
cv2.waitKey(0)
cv2.destroyAllWindows()Real-time Webcam Feed:
import cv2
cap = cv2.VideoCapture(0) # 0 = default webcam
while True:
ret, frame = cap.read()
if not ret:
break
# Your processing here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow("Webcam Feed", gray)
if cv2.waitKey(1) & 0xFF == ord('q'): # Press Q to quit
break
cap.release()
cv2.destroyAllWindows()Each image = NumPy array of shape (Height, Width, Channels)
BGR Image: shape = (480, 640, 3) โ OpenCV default color order
Gray Image: shape = (480, 640) โ Single channel
| Function | Description |
|---|---|
cv2.imread() |
Load image from disk |
cv2.VideoCapture() |
Open camera or video file |
cv2.cvtColor() |
Convert color spaces (BGR โ Gray โ HSV) |
cv2.GaussianBlur() |
Smooth image to reduce noise |
cv2.Canny() |
Detect edges using gradient magnitude |
cv2.findContours() |
Detect object boundaries |
cv2.rectangle() |
Draw bounding boxes |
cv2.putText() |
Overlay text labels on frames |
cv2.imshow() |
Display image/frame in window |
BGR โ Default in OpenCV
RGB โ Standard (swap R and B from BGR)
GRAY โ Single channel, used for detection
HSV โ Hue-Saturation-Value, great for color filtering
| Operation | Input | Output |
|---|---|---|
| Grayscale | Color image | Single-channel gray image |
| Edge Detection | Grayscale image | White edges on black background |
| Face Detection | Portrait photo | Face bounded by blue rectangle |
| Contour Detection | Binary image | Green contours drawn on objects |
| Webcam Feed | Live video | Real-time annotated frames |
| Domain | Application |
|---|---|
| ๐ Security | Real-time face detection & surveillance |
| ๐ญ Manufacturing | Defect detection on production lines |
| ๐ Autonomous Vehicles | Lane detection, obstacle recognition |
| ๐ฅ Healthcare | Medical image analysis |
| ๐ฆ Retail | Product recognition & shelf monitoring |
| ๐ฎ Gaming / AR | Gesture control, augmented reality |
| ๐ธ Photography | Auto-enhancement, object segmentation |
| Problem | Solution |
|---|---|
ModuleNotFoundError: cv2 |
Run pip install opencv-python |
| Camera not opening | Check VideoCapture(0) index; try 1 or 2 for external cams |
| Window not displaying | Ensure you have a display; use opencv-python not headless |
imshow crashes on Linux |
Install python3-tk or use matplotlib for display |
| Slow FPS on webcam | Reduce resolution: cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640) |
| Face not detected | Tune scaleFactor and minNeighbors in detectMultiScale() |
- Deep learning-based object detection (YOLOv8)
- Multi-face tracking across video frames
- Gesture recognition with MediaPipe
- OCR integration (Tesseract)
- Real-time emotion detection
- Streamlit web UI for live demo
Contributions are welcome!
# 1. Fork the repo on GitHub
# 2. Clone your fork
git clone https://github.com/your-username/Computer-Vision.git
# 3. Create a feature branch
git checkout -b feature/your-feature-name
# 4. Make your changes & commit
git commit -m "feat: describe your change"
# 5. Push & open a Pull Request
git push origin feature/your-feature-nameIdeas for contributions:
- ๐ฏ Add YOLOv8 / MobileNet object detection
- ๐๏ธ Hand gesture recognition with MediaPipe
- ๐ Add FPS counter and performance metrics
- ๐ Build a Streamlit/Gradio live demo UI
This project is licensed under the Apache 2.0 License โ see the LICENSE file for details.
Made with โค๏ธ by eddiebrock911
โญ Star this repo if you found it useful!