Master OpenCV from Pixels to Real-World Projects in 17 Hands-on Chapters
OpenCV ่ฎก็ฎๆบ่ง่งๅฎๆ โ From Basics to Deep-Learning-Powered Vision
๐ฌ๐ง English โข ๐จ๐ณ ไธญๆ
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.