【实例简介】
双目视觉,根据块匹配方法的视差图生成。依据Matlab生成视差图。
Dbasic= zeros(size(leftI),'single')
disparity range 15;
Selects (2*halfBlocksize+1)-by-(2*halfBlocksize+1) block
halfblocksize =3
blocksize 2*halfblocksize+1
Allocate space for all template matchers
tats cell(blocksize)
g Scan over all rows
for m=1: size(leftI, 1)
Set min/max row bounds for image block
inr=max(l, m-halfBlocksize);
maxr min(size(leftI, 1), mthalfBlocksize)i
‰ Scan over a11 columns
for n=1: size(leftI, 2
minc =max(1, n-halfBlocksize);
maxc min(size(leftI, 2),nthalfBlocksize)
Compute disparity bounds
mind max( -disparityRange, 1-minc i
maxd min( disparityRange, size(leftI, 2)-maxc
9 Construct template and region of interest
template rightI(minr: maxr, minc: maxc);
templateCenter floor((size(template)+1)/2)
roi = [minr+template Center(1)-2
mincttemplateCenter(2)+mind-2
1 maxd-mind+1]
Lookup proper TemplateMatcher object, create if empty
if isempty( tmatssize(template, 1),size(template, 2)1)
tmatsisize(template, 1),size(template, 2)1
video. TemplateMatcher( ROIInputPort', true);
thisTemplateMatcher tmatsfsize(template, 1),size(template, 2));
Run TemplateMatcher object
loc step( thisTemplateMatcher, leftI, template, roi);
basic(m)
m,n)=1oc(2)-roi(2)
nd
end
end
In the results bclow, the basic block matching docs well, as the correct shape of thc stcrco
scene is recovered. However, there are noisy patches and bad depth estimates everywhere,
especially on the ceiling. These are caused when no strong image features appear inside of
the 7-by-7-pixel windows being compared. Then the matching process is subject to noise
since each pixel chooses its disparity independently of all the other pixels
For display purposes, we saturate the depth map to have only positive values. In general
slight angular misalignment of the stereo cameras used for image acquisition can allow both
positive and negative disparities to appear validly in the depth map In this case, however, the
stereo cameras were near perfectly parallel, so the true disparities have only one sign. Thus
this correction is valid
figure(3), clf;
imshow(Dbasic, []), axis image, colormap( jet), colorbar
caxis(lo disparity d);
title( ' depth map from basic block matching)
Depth map from basic black matching
10
Step 3. Sub-pixel estimation
The disparity estimates returned by block matching are all integer-valued so the above depth
map exhibits contouring effects where there