Camera Capture with OpenCV
Build a repeatable capture and preprocessing workflow with runnable Python examples.
Run the sample lab
OpenCV field lab640 × 360
InputBGR frame
ResultCanny edges
Table of contents
View all 59 chapters
- Camera Selection and Interfaces Free sample
- OpenCV Environment Setup Free sample
- OpenCV Environment Setup Free sample
- Reading Local Cameras Free sample
- Reading Local Cameras
- Reading IP Cameras (RTSP)
- Reading IP Cameras (RTSP)
- Chapter 5 Title
- Frame Buffering and Queues
- Chapter 6 Title
- Color Space Conversion (BGR to RGB)
- Chapter 7 Title
- Basic Image Thresholding
- Chapter 8 Title
- Morphological Operations
- Chapter 9 Title
- Edge Detection (Canny/Sobel)
- Chapter 10 Title
- Contour Detection and Properties
- Chapter 11 Title
- Histogram Equalization
- Chapter 12 Title
- Camera Calibration Matrix
- Chapter 13 Title
- Distortion Coefficients
- Chapter 14 Title
- Perspective Transformation
- Chapter 15 Title
- Object Detection with Haar Cascades
- Chapter 16 Title
- Introduction to Deep Learning Models
- Chapter 17 Title
- Running YOLOv5 with OpenCV
- Chapter 18 Title
- Face Landmarks and Tracking
- Chapter 19 Title
- Optical Flow Basics
- Chapter 20 Title
- Feature Matching (SIFT/ORB)
- Chapter 21 Title
- Video Stabilization Techniques
- Chapter 22 Title
- Multithreaded Video Processing
- Chapter 23 Title
- Integrating OpenVINO Toolkit
- Chapter 24 Title
- Hardware Acceleration (GPU/DSP)
- Chapter 25 Title
- Deploying on Raspberry Pi
- Chapter 26 Title
- Deploying on NVIDIA Jetson
- Chapter 27 Title
- Real-time Data Streaming
- Chapter 28 Title
- Customizing Debug Overlays
- Chapter 29 Title
- Logging and Error Handling
- Chapter 30 Title
- 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
- Choose a camera and an interface
- Set up OpenCV on Windows, Linux, and macOS
- Read and inspect a local camera
- Read an IP camera over RTSP
- Read a video file as a repeatable input
- Understand frame layout, data types, and views
- Display images and video without starving the event loop
- Save images and video that can be played back
- Convert color spaces with an explicit goal
- Resize and crop while keeping coordinates traceable
- Rotate and flip without losing the field of view
- Filter noise while measuring retained detail
- Turn grayscale intensities into useful masks
- Detect edges and interpret the response
- Clean binary shapes with morphological operations
- Measure contours, hierarchy, and area
- Improve local contrast without amplifying artifacts
- Use image pyramids and reconstruct across scales
- Find a template and consolidate overlapping hits
- Detect local features and validate matches geometrically
- Estimate motion with sparse and dense optical flow
- Learn a background model and preserve its state
- Use frame differences without mistaking change for a silhouette
- Choose a bounded capture queue and a frame policy
- Bridge blocking capture into an asyncio application
- Measure the slow stage before optimizing video
- Evaluate hardware acceleration on Jetson, Raspberry Pi, and Intel
- Record and replay streams with verifiable event indexes
- Calibrate a camera and verify the geometry
- 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 instructionsTechnical references
OpenCV Environment Setup
Check whether VideoCapture failed, produced an empty frame, or returned a valid but dark image.
OpenCV Environment Setup
Reading Local Cameras
Measure local read and queue time before changing RTSP transport, camera encoding, or frame policy.
Reading Local Cameras
Reading IP Cameras (RTSP)
Reproduce how a two-frame queue behaves when a consumer falls behind a live video source.