Skip to content

tinyzqh/Opencv-Computer-Vision-Practice-Python-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฏ OpenCV Computer Vision Practice (Python)

Master OpenCV from Pixels to Real-World Projects in 17 Hands-on Chapters
OpenCV ่ฎก็ฎ—ๆœบ่ง†่ง‰ๅฎžๆˆ˜ โ€” From Basics to Deep-Learning-Powered Vision

๐Ÿ‡ฌ๐Ÿ‡ง English โ€ข ๐Ÿ‡จ๐Ÿ‡ณ ไธญๆ–‡

Stars Forks Issues Python OpenCV PyTorch Tests License

Highlights โ€ข Curriculum โ€ข Quick Start โ€ข Showcase โ€ข Learning Path โ€ข Contributing


๐Ÿ“– About This Repository

A progressive, project-driven OpenCV learning repository. It walks you from the very basics โ€” reading an image, thresholding, morphology โ€” all the way to production-flavored projects: credit-card OCR, panorama stitching, parking-spot detection, exam-sheet grading, deep-learning inference with the DNN module, multi-object tracking, and drowsiness detection.

Every chapter ships with:

  • โœ… Runnable Python code (built on opencv-python / numpy)
  • โœ… Bundled images & videos โ€” clone the repo and reproduce results instantly
  • โœ… A matching long-form article (Chinese WeChat column, linked in the table below)

๐Ÿ’ก Who is this for? CV beginners, engineers brushing up traditional vision, students preparing for CV interviews, and developers who want to combine classical OpenCV with modern deep learning.


โœจ Highlights

๐Ÿš€ 17 Progressive Chapters ๐Ÿ›  9+ End-to-End Projects ๐Ÿ“ฆ Batteries Included
Smooth difficulty curve from pixel ops to DNN inference Credit-card OCR ยท panorama ยท parking lot ยท OMR ยท drowsiness ยท more Data, models and code โ€” just python xxx.py
๐Ÿ“ Article per Chapter ๐ŸŽ“ Classic CV + Deep Learning ๐ŸŒฑ Actively Maintained
Each chapter has a deep-dive article explaining theory & code Harris / SIFT / Optical Flow + Caffe / dlib / DNN Issues and PRs warmly welcomed

๐Ÿ“š Curriculum

# Chapter Keywords Companion Article Code Folder
01 Introduction Roadmap & motivation ๐Ÿ“– Kickoff post โ€”
02 Image Basics Read image / video ยท ROI ยท channels ยท blending ยท padding ๐Ÿ“– Image Basics Chapter 2
03 Thresholding & Smoothing Binarization ยท mean / Gaussian / median blur ๐Ÿ“– Thresholding & Smoothing Chapter 3
04 Morphological Operations Erode ยท Dilate ยท Open / Close ยท Top-hat / Black-hat ๐Ÿ“– Morphology Chapter 4
05 Image Gradients Sobel ยท Scharr ยท Laplacian ๐Ÿ“– Gradients โ€”
06 Edge Detection Canny full pipeline ๐Ÿ“– Edge Detection โ€”
07 Pyramids & Contours Gaussian / Laplacian pyramid ยท contour approximation ๐Ÿ“– Pyramids & Contours โ€”
08 Histograms & Fourier Transform Histogram ยท DFT ยท frequency-domain filtering ๐Ÿ“– Histograms & Fourier โ€”
09 ๐Ÿ’ณ Project 1: Credit-Card OCR Template matching ยท morphology ยท perspective ๐Ÿ“– Credit-Card OCR (with code) Chapter 9
10 Corner Detection Harris ๐Ÿ“– Harris Corners Chapter 11
11 SIFT Features Scale-invariant feature transform ๐Ÿ“– SIFT Chapter 12
12 ๐ŸŒ„ Project 2: Panorama Stitching Feature matching ยท homography ยท Stitcher ๐Ÿ“– Panorama Stitching Chapter 13
13 ๐Ÿ…ฟ๏ธ Project 3: Parking-Spot Detection Video processing ยท CNN classification ยท occupancy state ๐Ÿ“– Parking Lot Chapter 14
14 ๐Ÿ“ Project 4: OMR Sheet Grading Perspective transform ยท contour sorting ยท bubble detection ๐Ÿ“– OMR / Answer Sheet Chapter 15
15 ๐ŸŽฅ Project 5: Background Subtraction MOG2 ยท KNN ยท foreground extraction ๐Ÿ“– Background Modeling Chapter 16
16 ๐ŸŽž Project 6: Optical Flow Lucas-Kanade optical flow ๐Ÿ“– Optical Flow Chapter 17
17 ๐Ÿง  Project 7: OpenCV DNN Caffe ยท GoogleNet ยท image classification ๐Ÿ“– OpenCV DNN Chapter 18
18 ๐Ÿš— Project 8: Multi-Object Tracking dlib ยท multithreaded tracking code only Chapter 19
19 ๐Ÿ˜ด Project 9: Drowsiness Detection Facial landmarks ยท EAR ยท blink / yawn detection code only Chapter 21

โญ Found it useful? Drop a Star so more people can discover it!


๐Ÿš€ Quick Start

1. Clone the repository

git clone https://github.com/tinyzqh/Opencv-Computer-Vision-Practice-Python-.git
cd Opencv-Computer-Vision-Practice-Python-

2. Install dependencies

We recommend an isolated environment with conda or venv:

pip install -r requirements.txt

That single file pulls everything you need: OpenCV (contrib build, for SIFT and legacy trackers), NumPy, Matplotlib, imutils, PyTorch + torchvision (for Chapter 14), dlib and SciPy (for Chapter 19 & 21).

Click to expand โ€” manual install
# Core
pip install "opencv-contrib-python>=4.5,<5.0" numpy matplotlib

# Extras used by selected chapters
pip install imutils                       # Chapter 9 / 15
pip install torch torchvision             # Chapter 14 โ€” Parking Lot (PyTorch)
pip install dlib scipy                    # Chapter 19 / 21 โ€” Tracking & Drowsiness

โœ… Tested on Python 3.12 + OpenCV 4.13 + PyTorch 2.11 + NumPy 2.4. All 32 example scripts run end-to-end. The codebase has been adapted to modern OpenCV 4.x (new findContours return shape, cv2.legacy.* trackers, strict integer coordinate types) โ€” no version pinning gymnastics required.

3. Run any example

# Credit-card OCR
cd "Chapter 9"
python ocr_template_match.py --image images/credit_card_01.png --template ocr_a_reference.png

# Panorama stitching
cd "Chapter 13"
python ImageStiching.py

# Background subtraction
cd "Chapter 16"
python "back model.py"

# Parking-spot detection (Chapter 14) โ€” two-step
cd "Chapter 14"
python train.py           # transfer-learning a VGG16 classifier (~90% val acc)
python park_test.py       # run the full detection + classification pipeline

๐Ÿ–ผ Project Showcase

Project What You Will Learn Folder
๐Ÿ’ณ Credit-Card OCR Combine template matching with morphology to solve real-world OCR Chapter 9
๐ŸŒ„ Panorama Stitching SIFT keypoint matching + homography + image blending Chapter 13
๐Ÿ…ฟ๏ธ Parking-Spot Detection Classical CV to segment ROIs + a PyTorch VGG16 transfer-learning classifier (90%+ val acc) โ€” end-to-end Chapter 14
๐Ÿ“ OMR Sheet Grading Perspective rectification + contour sorting + bubble recognition Chapter 15
๐Ÿง  DNN Image Classification Load a Caffe model directly from OpenCV โ€” no DL framework needed Chapter 18
๐Ÿš— Multi-Object Tracking dlib correlation tracker + multithreading for real-time tracking Chapter 19
๐Ÿ˜ด Drowsiness Detection 68-point facial landmarks + EAR โ€” build a tiny app that keeps you awake Chapter 21

๐Ÿ—บ Learning Path

Basics (Ch.2~4)
        โ”‚
        โ–ผ
Feature Engineering (Ch.5~8) โ”€โ”€โ–บ Histograms / Frequency / Edges / Contours
        โ”‚
        โ–ผ
Keypoint Detection (Ch.10~11) โ”€โ”€โ–บ Harris / SIFT
        โ”‚
        โ”œโ”€โ”€โ–บ ๐Ÿ’ณ First project: Credit-Card OCR (Ch.9)
        โ”‚
        โ–ผ
Registration & Stitching (Ch.12) โ”€โ”€โ–บ ๐ŸŒ„ Panorama
        โ”‚
        โ–ผ
Video & Temporal Vision (Ch.16~17) โ”€โ”€โ–บ ๐ŸŽฅ Background Subtraction / ๐ŸŽž Optical Flow
        โ”‚
        โ”œโ”€โ”€โ–บ ๐Ÿ…ฟ๏ธ Parking-Spot Detection (Ch.14)
        โ”œโ”€โ”€โ–บ ๐Ÿ“ OMR Sheet Grading (Ch.15)
        โ”‚
        โ–ผ
Meets Deep Learning (Ch.18~21) โ”€โ”€โ–บ ๐Ÿง  DNN / ๐Ÿš— Multi-Tracking / ๐Ÿ˜ด Drowsiness

๐Ÿ“ฆ Repository Structure

Opencv-Computer-Vision-Practice-Python-/
โ”œโ”€โ”€ Chapter 2/   # Image basics (I/O, ROI, channels, blending, padding)
โ”œโ”€โ”€ Chapter 3/   # Thresholding
โ”œโ”€โ”€ Chapter 4/   # Morphology (erode / dilate / open / close / gradient / hat)
โ”œโ”€โ”€ Chapter 9/   # ๐Ÿ’ณ Credit-Card OCR
โ”œโ”€โ”€ Chapter 11/  # Harris corners
โ”œโ”€โ”€ Chapter 12/  # SIFT & feature matching
โ”œโ”€โ”€ Chapter 13/  # ๐ŸŒ„ Panorama stitching
โ”œโ”€โ”€ Chapter 14/  # ๐Ÿ…ฟ๏ธ Parking-spot detection (with CNN training data)
โ”œโ”€โ”€ Chapter 15/  # ๐Ÿ“ OMR sheet grading
โ”œโ”€โ”€ Chapter 16/  # ๐ŸŽฅ Background subtraction
โ”œโ”€โ”€ Chapter 17/  # ๐ŸŽž Optical flow
โ”œโ”€โ”€ Chapter 18/  # ๐Ÿง  OpenCV DNN (Caffe / GoogleNet)
โ”œโ”€โ”€ Chapter 19/  # ๐Ÿš— Multi-object tracking (dlib + multithreading)
โ”œโ”€โ”€ Chapter 21/  # ๐Ÿ˜ด Drowsiness & blink detection
โ”œโ”€โ”€ requirements.txt   # one-shot pip install
โ”œโ”€โ”€ COMPATIBILITY.md   # OpenCV 4.x / NumPy 2 / PyTorch porting notes
โ”œโ”€โ”€ README.md          # English (default)
โ””โ”€โ”€ README_CN.md       # ไธญๆ–‡็‰ˆ

๐Ÿ›  Troubleshooting

Running into a findContours unpack error, a missing TrackerKCF_create, or a Keras import in Chapter 14? See COMPATIBILITY.md โ€” every porting tweak (and the modern API it now uses) is documented there.


๐Ÿค Contributing

The material is based on notes from the NetEase Cloud Classroom course ใ€ŠOpenCV Computer Vision Practiceใ€‹, reorganized and extended with comments and additional examples.

You are very welcome to contribute in any form:

  • ๐Ÿž Found a bug or broken example? โ€” open an Issue
  • โœจ Want to add a new project? โ€” send a PR
  • ๐Ÿ“ Notes / typo fixes / extra explanations? โ€” PR the README or add a notes/ folder
  • โญ Got value out of it? โ€” a Star is the simplest and most powerful thank-you

๐Ÿ“œ License

  • The code in this repository is released under the MIT License โ€” feel free to study, modify and build on it.
  • The companion WeChat articles are shared for educational purposes and do not necessarily reflect the platform's views.
  • Any referenced course material remains copyright of the original course authors. Please contact the maintainer if you believe there is an infringement.

If this repo helped you skip a few miles of detours, please consider giving it a โญ Star โ€” so it can light the path for other learners.

Made with โค๏ธ for everyone who loves computer vision.

About

OpenCV Computer Vision Practice (Python)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages