Stereo block matching
Find horizontal correspondences between rectified stereo images using local block similarity.
Two cameras observe the same scene point from different positions.
Rectify images so corresponding points share scanlines.
Compare a local block across candidate horizontal shifts.
Select a supported disparity and reject weak or inconsistent matches.
Select a supported disparity and reject weak or inconsistent matches.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Compute disparity from rectified grayscale stereo views. The second image must use the same rectification. Native values are disparity pixels; negative values denote invalid matches.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Estimate a fast, coarse disparity map from a calibrated stereo pair.
How it works
- 01Rectify images so corresponding points share scanlines.
- 02Compare a local block across candidate horizontal shifts.
- 03Select a supported disparity and reject weak or inconsistent matches.
depth ∝ focal length × baseline / disparity
What to tune
numDisparities sets search range; blockSize trades detail against stability; uniqueness and texture settings reject uncertain matches.
Where it breaks down
Uniform regions, reflections and occlusion cause invalid disparities. The raw output uses a fixed-point scale and needs proper conversion.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Camera calibration
Estimate a camera’s intrinsic parameters and lens distortion from known target geometry.
Lens undistortion
Invert a calibrated lens model to map distorted observations onto an idealized camera image.
Perspective-n-point pose
Estimate a camera-relative object pose from known 3D points and their 2D image observations.
Fundamental and essential matrices
Constrain where a point from one camera view can appear in another.