Master OpenCV from Pixels to Real-World Projects in 17 Hands-on Chapters
OpenCV 计算机视觉实战 — From Basics to Deep-Learning-Powered Vision
Highlights • Curriculum • Quick Start • Showcase • Learning Path • Contributing
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.
| 🚀 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 |
| # | 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 | 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!
git clone https://github.com/tinyzqh/Opencv-Computer-Vision-Practice-Python-.git
cd Opencv-Computer-Vision-Practice-Python-We recommend an isolated environment with conda or venv:
pip install -r requirements.txtThat 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
findContoursreturn shape,cv2.legacy.*trackers, strict integer coordinate types) — no version pinning gymnastics required.
# 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 | 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 |
| 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 |
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
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 # 中文版
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.
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
- 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.