资源简介
立体视觉,求取视差图,效果不错,可以使用
代码片段和文件信息
hIdtc = vision.ImageDataTypeConverter;
hCsc = vision.ColorSpaceConverter(‘Conversion‘‘RGB to intensity‘);
leftI3chan = step(hIdtcimread(‘shudxc1.png‘));
leftI = step(hCscleftI3chan);
rightI3chan = step(hIdtcimread(‘shudxc2.png‘));
rightI = step(hCscrightI3chan);
figure(1) clf;
imshow(rightI3chan) title(‘Right image‘);
figure(2) clf;
imshowpair(rightIleftI‘ColorChannels‘‘red-cyan‘);axis image;
title(‘Color composite (right=red left=cyan)‘);
Dbasic = zeros(size(leftI) ‘single‘);
disparityRange = 16;
% Selects (2*halfBlockSize+1)-by-(2*halfBlockSize+1) block.
halfBlockSize = 4;
blockSize = 2*halfBlockSize+1;
% Allocate space for all template matcher System objects.
tmats = cell(blockSize);
% Initialize progress bar
hWaitBar = waitbar(0 ‘Performing basic block matching...‘);
nRowsLeft = size(leftI 1);
% Scan over all rows.
for m=1:nRowsLeft
% Set min/max row bounds for image block.
minr = max(1m-halfBlockSize);
maxr = min(nRowsLeftm+halfBlockSize);
% Scan over all columns.
for n=1:size(leftI2)
minc = max(1n-halfBlockSize);
maxc = min(size(leftI2)n+halfBlockSize);
% Compute disparity bounds.
mind = max( -disparityRange 1-minc );
maxd = min( disparityRange size(leftI2)-maxc );
% Construct template and region of interest.
template = rightI(minr:maxrminc:maxc);
templateCenter = floor((size(template)+1)/2);
roi = [minc+templateCenter(2)+mind-1 ...
minr+templateCenter(1)-1 ...
maxd-mind+1 1];
% Lookup proper TemplateMatcher object; create if empty.
if isempty(tmats{size(template1)size(template2)})
tmats{size(template1)size(template2)} = ...
vision.TemplateMatcher(‘ROIInputPort‘true);
end
thisTemplateMatcher = tmats{size(template1)size(template2)};
% Run TemplateMatcher object.
loc = step(thisTemplateMatcher leftI template roi);
Dbasic(mn) = loc(1) - roi(1) + mind;
end
waitbar(m/nRowsLefthWaitBar);
end
close(hWaitBar);
figure(3) clf;
imshow(Dbasic[]) axis image colormap(‘jet‘) colorbar;
caxis([0 disparityRange]);
title(‘Depth map from basic block matching‘);
DbasicSubpixel= zeros(size(leftI) ‘single‘);
tmats = cell(2*halfBlockSize+1);
hWaitBar=waitbar(0‘Performing sub-pixel estimation...‘);
for m=1:nRowsLeft
% Set min/max row bounds for image block.
minr = max(1m-halfBlockSize);
maxr = min(nRowsLeftm+halfBlockSize);
% Scan over all columns.
for n=1:size(leftI2)
minc = max(1n-halfBlockSize);
maxc = min(size(leftI2)n+halfBlockSize);
% Compute disparity bounds.
mind = max( -disparityRange 1-minc );
maxd = min( disparityRange size(leftI2)-maxc );
% Construct template and region of interest.
template = rightI(minr:maxrminc:maxc);
- 上一篇:matlab随机数生成大全
- 下一篇:MATLABR2016bMac破解版.txt
评论
共有 条评论