Semi-global stereo matching
Aggregate stereo matching costs along multiple directions while penalizing disparity jumps.
Two cameras observe the same scene point from different positions.
Compute local costs for each candidate disparity.
Accumulate costs along paths with small- and large-jump penalties.
Choose disparities and perform consistency or speckle filtering.
Choose disparities and perform consistency or speckle filtering.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Compute semi-global disparity from rectified grayscale views. The default translated pair only illustrates disparity, not metric depth.
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
Obtain more coherent depth maps than independent local block matching.
How it works
- 01Compute local costs for each candidate disparity.
- 02Accumulate costs along paths with small- and large-jump penalties.
- 03Choose disparities and perform consistency or speckle filtering.
matching cost + penalties for disparity changes
What to tune
P1 and P2 set smoothness penalties; mode changes path aggregation and cost; tune disparity range to camera geometry.
Where it breaks down
Smoothness can flatten thin structures and cross depth boundaries. It cannot create trustworthy depth where correspondence is absent.
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.