Skip to content
Tutorials Center
My learning

Topics

OpenCV Tutorial

Learn OpenCV step by step: 54 lessons in 12 chapters with examples, quizzes, diagrams and projects.

Start learning →

of lessons completed

Getting Started

  1. 1 What Is OpenCV? OpenCV is the open-source library for computer vision: images, video, edges, features and detection. See what it does, how it is built and how this course runs.
  2. 2 Installing OpenCV Install OpenCV with pip in a virtual environment. Choose between opencv-python, headless and contrib builds, verify cv2.__version__ and fix common errors.
  3. 3 Images Are NumPy Arrays In Python an OpenCV image is a NumPy array. Learn pixels, shape (height, width, channels), uint8 values and row-column order by building images from scratch.
  4. 4 Reading, Showing and Saving Images Load images with cv2.imread and its flags, show them with imshow and waitKey, save with imwrite, and avoid the None-on-bad-path trap. Includes headless options.
  5. 5 Mouse Events, Trackbars and Interactive Windows Make OpenCV windows interactive: setMouseCallback events, click coordinates and colors, drawing and cropping with the mouse, trackbars for live tuning, selectROI and waitKey.

Pixels and Color

  1. 6 Color Spaces: BGR, RGB, Gray and HSV Understand OpenCV's BGR channel order, convert with cvtColor, learn the grayscale formula and HSV hue, then rebuild gray and BGR-to-RGB with NumPy.
  2. 7 Accessing and Modifying Pixels Read and change pixels with NumPy indexing, slice a region of interest, split and merge channels, and avoid the view-versus-copy trap. Live examples included.
  3. 8 Data Types, Ranges and Saturation Learn why uint8 pixels wrap around, how OpenCV saturates instead, when to use float32 images in the 0-1 range, and how convertScaleAbs and normalize rescale values.
  4. 9 Drawing Shapes and Text Draw lines, rectangles, circles, polygons and text on images with OpenCV, understand thickness, filled shapes, anti-aliasing, and rebuild rectangle and line drawing in NumPy.

Geometric Transformations

  1. 10 Resizing, Cropping and Flipping Resize images with cv2.resize and its interpolation flags, keep the aspect ratio, crop by slicing, flip and rotate by 90 degrees, and rebuild nearest and bilinear resizing in NumPy.
  2. 11 Translation, Rotation and Affine Transforms Move, rotate and scale images with cv2.warpAffine and getRotationMatrix2D, read the 2x3 matrix, understand inverse mapping, and apply matrices to coordinates in NumPy.
  3. 12 Perspective Transforms and Document Scanning Straighten skewed photos with getPerspectiveTransform and warpPerspective, order four corner points, understand the 3x3 homography, and solve it yourself with NumPy.
  4. 13 Interpolation and Image Quality Compare INTER_NEAREST, LINEAR, CUBIC, LANCZOS4 and INTER_AREA, learn why shrinking causes aliasing, build image pyramids with pyrDown and pyrUp, and code a bilinear sampler.
  5. 14 Image Pyramids: pyrDown, pyrUp and Laplacian Pyramids Build Gaussian and Laplacian image pyramids with pyrDown and pyrUp, see why blurring comes before shrinking, and use pyramids for multi-scale search and seamless blending.

Image Processing

  1. 15 Thresholding Learn OpenCV thresholding: global binary modes, Otsu's automatic threshold and adaptive mean or Gaussian methods, with Otsu rebuilt in numpy that you can run.
  2. 16 Intensity Transformations: Negative, Log, Gamma and Contrast Stretching Change brightness and contrast pixel by pixel: negative, log, power-law (gamma), piecewise-linear stretching and lookup tables with cv2.LUT, plus NumPy versions you can run.
  3. 17 Histograms and Equalization Read an image histogram with calcHist, then fix flat contrast with stretching, equalizeHist and CLAHE. Equalization is rebuilt in numpy so you can run it.
  4. 18 Blurring and Noise Reduction Compare OpenCV's box, Gaussian, median and bilateral blurs, learn why kernel sizes are odd, and rebuild each filter in numpy to see how they treat noise.
  5. 19 Edge-Preserving Denoising, Non-Local Means and Inpainting Remove noise without blurring edges using bilateral filtering and non-local means, then repair scratches and unwanted objects with cv2.inpaint, with runnable NumPy models.
  6. 20 Kernels and filter2D Apply your own kernels with cv2.filter2D: convolution versus correlation, sharpening and emboss kernels, border types, and a 2D filter written in numpy.
  7. 21 Morphological Operations Learn erosion, dilation, opening, closing, gradient and top-hat in OpenCV, how structuring elements work, and run binary morphology written in numpy.
  8. 22 Arithmetic, Bitwise Ops and Masking Learn why cv2.add saturates but numpy wraps, how addWeighted blends images, and how inRange and bitwise_and build masks. Every idea is rebuilt in numpy.

Edges, Contours and Shapes

  1. 23 Gradients, Sobel and Laplacian Learn how image gradients find edges. Understand cv2.Sobel, cv2.Laplacian and cv2.Scharr, why CV_64F matters, and rebuild Sobel from scratch in NumPy.
  2. 24 Canny Edge Detection Understand cv2.Canny: Gaussian blur, gradients, non-maximum suppression and hysteresis. Learn how to pick thresholds, and run the four stages in NumPy.
  3. 25 Finding and Drawing Contours Learn cv2.findContours: retrieval modes, approximation methods, the hierarchy array, drawContours, and how contours relate to connected components.
  4. 26 Contour Features: Area, Perimeter and Bounding Boxes Measure contours with contourArea, arcLength, boundingRect, minAreaRect, minEnclosingCircle, convexHull and moments, and rebuild each measurement in Python.
  5. 27 Detecting Lines, Circles and Shapes Detect lines with HoughLines and HoughLinesP, circles with HoughCircles, and classify polygons with approxPolyDP. See the Hough accumulator in NumPy.
  6. 28 Blob Detection: Counting Dots, Circles and Ellipses Find and count blobs with SimpleBlobDetector and connectedComponentsWithStats: filter by area, circularity, convexity and inertia, detect circles and ellipses, with runnable NumPy models.
  7. 29 GrabCut: Foreground Extraction and Background Removal Cut out an object with cv2.grabCut: start from a rectangle or a mask, understand the four mask values and the GMM model, refine with strokes, and apply the result.

Features and Matching

  1. 30 Template Matching Find a small image inside a bigger one with cv2.matchTemplate. Compare the six methods, read minMaxLoc, find several matches, and see the limits with scale.
  2. 31 Corners and Keypoints: Harris, Shi-Tomasi, ORB Learn what makes a good image feature, then use cornerHarris, goodFeaturesToTrack and ORB in OpenCV. Compute the Harris response yourself with NumPy.
  3. 32 Feature Matching and Homography Match ORB and SIFT descriptors with BFMatcher and FLANN, filter with Lowe's ratio test, then fit a homography with RANSAC. Hamming and RANSAC in NumPy.
  4. 33 Image Registration: Aligning Images with ECC and Phase Correlation Align two images of the same scene: choose a motion model, estimate it with phase correlation, ECC or feature matching, warp the result, and fit an affine transform from point pairs.

Video and Cameras

  1. 34 Reading and Writing Video Read video files and webcams with cv2.VideoCapture, loop over frames, query fps and size, and save results with VideoWriter. Includes a NumPy frame-loop stand-in.
  2. 35 Processing Video Frame by Frame Build a fast OpenCV frame loop: resize for speed, time it with getTickCount, skip frames, and separate moving objects with MOG2, KNN or a running average.
  3. 36 Video Recipes: Duration, Slow Motion, Timestamps, Blending and More Practical OpenCV video tasks: read duration and FPS, extract frames, resize, add timestamps, slow motion, reverse playback, blend two videos, images to video and threaded reading.
  4. 37 Motion and Object Tracking Track objects in OpenCV with color masks, Lucas-Kanade optical flow, meanShift and CamShift, and CSRT or KCF trackers. Live NumPy flow and centroid tracker.

Detection with Machine Learning

  1. 38 Face Detection with Haar Cascades Detect faces with OpenCV's CascadeClassifier and tune detectMultiScale. Learn how Haar features and integral images work, with NumPy examples and privacy notes.
  2. 39 The dnn Module: Running Neural Networks Run neural networks with OpenCV's dnn module: load an ONNX model with readNet, build a blob, call forward, decode YOLO-style output and apply non-max suppression.
  3. 40 QR Codes, ArUco Markers and Text Detect and decode QR codes with QRCodeDetector, find ArUco markers and estimate distance, read text with a Tesseract bridge, and see how marker bits and IoU work.

Camera Geometry

  1. 41 Camera Calibration and Undistortion Learn the pinhole camera model, intrinsics and distortion coefficients, then see calibrateCamera and undistort used with chessboard images, plus projection in NumPy.
  2. 42 Stereo Vision and Depth Understand stereo vision: epipolar geometry, disparity, depth = f times B over d, StereoBM and StereoSGBM in OpenCV, and block matching you can run on tiny arrays.

Performance and Production

  1. 43 Making OpenCV Fast Speed up OpenCV code: avoid Python pixel loops, use vectorized NumPy and cv2 calls, work on ROIs, try UMat and OpenCL, set threads, and profile with real timings.
  2. 44 Common Mistakes and Debugging Fix the classic OpenCV bugs: BGR versus RGB, imread returning None, (x, y) versus (row, column), uint8 overflow, views versus copies, even kernels and headless imshow.
  3. 45 Testing Computer Vision Code Learn to test image-processing code with synthetic images, golden files, tolerance comparisons and fixed random seeds, using pytest-style asserts on NumPy arrays.

Projects

  1. 46 Project: Document Scanner Build a document scanner step by step: find the page, order its four corners, warp it flat with a homography and clean it with a threshold, with a live NumPy demo.
  2. 47 Project: Color Object Detector Build a color object detector: convert to HSV, threshold with inRange, clean the mask with morphology, then find contours and centroids. Live NumPy demo included.
  3. 48 Project: Lane Line Detection Build a lane line detector: grayscale, blur, Canny edges, a region mask, Hough lines and slope averaging. Includes a live NumPy demo on a synthetic road.
  4. 49 Project: Motion Detector Build a motion detector with frame differencing: gray, blur, absdiff, threshold, dilate and bounding boxes. Includes live NumPy demos on synthetic frames.
  5. 50 Project: Panorama Stitching Stitch two overlapping photos into a panorama: detect features, match them with a ratio test, fit a homography with RANSAC, then warp and blend. Live NumPy demo.
  6. 51 Project: Invisible Cloak Build the invisible cloak effect: capture a clean background, mask a cloth color in HSV (including the red hue wrap), clean the mask and replace those pixels with the background.

Practice and Review

  1. 52 Practice Exercises with Solutions Practice OpenCV ideas with 12 graded exercises on pixels, color, thresholds, filters, edges and contours. Every solution is a numpy stand-in you can run and edit.
  2. 53 OpenCV Interview Questions Prepare for computer vision interviews with OpenCV questions on BGR, kernels, Canny, Otsu, homography, ORB vs SIFT and speed, each with a small live check.
  3. 54 OpenCV Cheat Sheet A one-page OpenCV Python cheat sheet: functions grouped by task, argument order, shape and dtype reminders, and flag tables, with small runnable numpy checks.