Skip to content

eddiebrock911/Computer-Vision

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ‘๏ธ Computer Vision with Python

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


๐Ÿ“Œ Table of Contents


๐Ÿง  Overview

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.


โœจ Features

  • ๐Ÿ‘๏ธ 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

โš™๏ธ How It Works

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

๐Ÿ—‚๏ธ Project Structure

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.


๐Ÿ› ๏ธ Tech Stack

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

๐Ÿ“ฆ Installation

1. Clone the repository:

git clone https://github.com/eddiebrock911/Computer-Vision.git
cd Computer-Vision

2. Create & activate a virtual environment:

# Create
python -m venv venv

# Activate โ€” Linux/Mac
source venv/bin/activate

# Activate โ€” Windows
venv\Scripts\activate

3. Install dependencies:

pip install opencv-python numpy matplotlib

For headless environments (servers without display):

pip install opencv-python-headless numpy

โ–ถ๏ธ Usage

Run the main script:

python vision1.py

Common 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()

๐Ÿ“š Core Concepts

Image Representation

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

Key OpenCV Functions

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

Color Spaces

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

๐Ÿ“‹ Example Output

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

๐Ÿ’ก Use Cases

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

๐Ÿ› Troubleshooting

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()

๐Ÿš€ Future Enhancements

  • 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

๐Ÿค Contributing

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-name

Ideas 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

๐Ÿ“„ License

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!

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages