Skip to content
Computer vision

Camera Capture with OpenCV

Build a repeatable capture and preprocessing workflow with runnable Python examples.

Run the sample lab

OpenCV field lab640 × 360
Decoded test frame with three colored shapes and a moving white block. InputBGR frame
Canny edge map showing white outlines of the same shapes against black. ResultCanny edges
Video fileGrayscaleEdge map

Table of contents

View all 59 chapters
  1. Camera Selection and Interfaces Free sample
  2. OpenCV Environment Setup Free sample
  3. OpenCV Environment Setup Free sample
  4. Reading Local Cameras Free sample
  5. Reading Local Cameras
  6. Reading IP Cameras (RTSP)
  7. Reading IP Cameras (RTSP)
  8. Chapter 5 Title
  9. Frame Buffering and Queues
  10. Chapter 6 Title
  11. Color Space Conversion (BGR to RGB)
  12. Chapter 7 Title
  13. Basic Image Thresholding
  14. Chapter 8 Title
  15. Morphological Operations
  16. Chapter 9 Title
  17. Edge Detection (Canny/Sobel)
  18. Chapter 10 Title
  19. Contour Detection and Properties
  20. Chapter 11 Title
  21. Histogram Equalization
  22. Chapter 12 Title
  23. Camera Calibration Matrix
  24. Chapter 13 Title
  25. Distortion Coefficients
  26. Chapter 14 Title
  27. Perspective Transformation
  28. Chapter 15 Title
  29. Object Detection with Haar Cascades
  30. Chapter 16 Title
  31. Introduction to Deep Learning Models
  32. Chapter 17 Title
  33. Running YOLOv5 with OpenCV
  34. Chapter 18 Title
  35. Face Landmarks and Tracking
  36. Chapter 19 Title
  37. Optical Flow Basics
  38. Chapter 20 Title
  39. Feature Matching (SIFT/ORB)
  40. Chapter 21 Title
  41. Video Stabilization Techniques
  42. Chapter 22 Title
  43. Multithreaded Video Processing
  44. Chapter 23 Title
  45. Integrating OpenVINO Toolkit
  46. Chapter 24 Title
  47. Hardware Acceleration (GPU/DSP)
  48. Chapter 25 Title
  49. Deploying on Raspberry Pi
  50. Chapter 26 Title
  51. Deploying on NVIDIA Jetson
  52. Chapter 27 Title
  53. Real-time Data Streaming
  54. Chapter 28 Title
  55. Customizing Debug Overlays
  56. Chapter 29 Title
  57. Logging and Error Handling
  58. Chapter 30 Title
  59. Building a Final Application

What’s included

30 English HTML chapters

Open the guide offline.

33 Python files

Run chapter experiments and the monitoring pipeline.

Synthetic test inputs

Use known video, image, and calibration fixtures.

Setup instructions

Start with the CPU lab. Try optional C++ or OpenVINO separately.

Table of contents

  1. Choose a camera and an interface
  2. Set up OpenCV on Windows, Linux, and macOS
  3. Read and inspect a local camera
  4. Read an IP camera over RTSP
  5. Read a video file as a repeatable input
  6. Understand frame layout, data types, and views
  7. Display images and video without starving the event loop
  8. Save images and video that can be played back
  9. Convert color spaces with an explicit goal
  10. Resize and crop while keeping coordinates traceable
  11. Rotate and flip without losing the field of view
  12. Filter noise while measuring retained detail
  13. Turn grayscale intensities into useful masks
  14. Detect edges and interpret the response
  15. Clean binary shapes with morphological operations
  16. Measure contours, hierarchy, and area
  17. Improve local contrast without amplifying artifacts
  18. Use image pyramids and reconstruct across scales
  19. Find a template and consolidate overlapping hits
  20. Detect local features and validate matches geometrically
  21. Estimate motion with sparse and dense optical flow
  22. Learn a background model and preserve its state
  23. Use frame differences without mistaking change for a silhouette
  24. Choose a bounded capture queue and a frame policy
  25. Bridge blocking capture into an asyncio application
  26. Measure the slow stage before optimizing video
  27. Evaluate hardware acceleration on Jetson, Raspberry Pi, and Intel
  28. Record and replay streams with verifiable event indexes
  29. Calibrate a camera and verify the geometry
  30. Build and test a real-time monitoring pipeline

Requirements and license

Python 3.12 is recommended. Core experiments use OpenCV and NumPy with bundled synthetic fixtures. Live capture and accelerated paths need supported hardware.

Read the download instructions

Technical references

OpenCV Environment Setup

Check whether VideoCapture failed, produced an empty frame, or returned a valid but dark image.

Reading Local Cameras

Measure local read and queue time before changing RTSP transport, camera encoding, or frame policy.