Skip to content

Semi-global stereo matching

Aggregate stereo matching costs along multiple directions while penalizing disparity jumps.

Try it on your image ↓

VISUAL WALKTHROUGH3D vision
REFERENCE INPUTRectified stereo observations

Two cameras observe the same scene point from different positions.

RESULTDisparity indicates relative depth

Choose disparities and perform consistency or speckle filtering.

STEP 03 / 03

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

YOUR IMAGE · REAL OPENCV

Experiment at pixel level

Open full lab ↗

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.

Input448 × 320
OutputWaiting for a result

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
Hover to inspect. Click to pin a pixel.
Input
Select a pixel

Output
Select a pixel

Sample models and licenses

When to use it

Obtain more coherent depth maps than independent local block matching.

How it works

  1. 01Compute local costs for each candidate disparity.
  2. 02Accumulate costs along paths with small- and large-jump penalties.
  3. 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.