法一:
%%
% 清理空间
clc;
clear;
close all;
%%
% 导入立体标定参数
load stereoParams.mat
% 立体参数的可视化
figure;
showExtrinsics(stereoParams);
%%
% 导入数据
frameLeft = imread('pattern_cam1_im1.png');
frameRight = imread('pattern_cam2_im1.png');
[frameLeftRect, frameRightRect] = ...
rectifyStereoImages(frameLeft, frameRight, stereoParams);
figure;
imshow(stereoAnaglyph(frameLeftRect, frameRightRect));
title('Rectified Frames');
%%
% 视差计算
frameLeftGray = rgb2gray(frameLeftRect);
frameRightGray = rgb2gray(frameRightRect);
disparityMap = disparity(frameLeftGray, frameRightGray);
figure;
imshow(disparityMap, [0, 64]);