资源简介
逆透视变换详解 及 代码实现(二) 中的相关代码!!
http://blog.csdn.net/yeyang911/article/details/51915348
轻松掌握逆透视变换!
代码片段和文件信息
%% LoadInfo [cameraInfo ipmInfo]
[cameraInfo ipmInfo] = GetInfo;
% GetInfo the information IPM need
%% IPM
outImage = zeros(ipmInfo.ipmHeightipmInfo.ipmWidth);
I = imread(‘IMG00996.jpg‘);
R = I(::1);
[Rheight Rwidth] = size(R);
u = Rheight;
v = Rwidth;
vpp = GetVanishingPoint(cameraInfo);
vp.x = vpp(1);
vp.y = vpp(2);
uvLimitsp = [ vp.x ipmInfo.ipmRight ipmInfo.ipmLeft vp.x;
ipmInfo.ipmTop ipmInfo.ipmTop ipmInfo.ipmTop ipmInfo.ipmBottom];
xyLimits = TransformImage2Ground(uvLimitspcameraInfo);
row1 = xyLimits(1:);
row2 = xyLimits(2:);
xfMin = min(row1); xfMax = max(row1);
yfMin = min(row2); yfMax = max(row2);
[outRow outCol] = size(outImage);
stepRow = (yfMax - yfMin)/outRow;
stepCol = (xfMax - xfMin)/outCol;
xyGrid = zeros(2outRow*outCol);
y = yfMax-0.5*stepRow;
for i = 1:outRow
x = xfMin+0.5*stepCol;
for j = 1:outCol
xyGrid(1(i-1)*outCol+j) = x;
xyGrid(2(i-1)*outCol+j) = y;
x = x + stepCol;
end
y = y - stepRow;
end
%TransformGround2Image
uvGrid = TransformGround2Image(xyGridcameraInfo);
% 图像均值
means = mean(R(:))/255;
RR = double(R)/255;
for i=1:outRow
for j = 1:outCol;
ui = uvGrid(1(i-1)*outCol+j);
vi = uvGrid(2(i-1)*outCol+j);
if (uiipmInfo.ipmRight || viipmInfo.ipmBottom)
outImage(ij) = means;
else
x1 = int32(ui); x2 = int32(ui+1);
y1 = int32(vi); y2 = int32(vi+1);
x = ui-double(x1) ; y = vi-double(y1);
val = double(RR(y1x1))*(1-x)*(1-y)+double(RR(y1x2))*x*(1-y)+double(RR(y2x1))*(1-x)*y+double(RR(y2x2))*x*y;
outImage(ij) = val;
end
end
end
%% 显示结果
figureimshow(outImage);
imwrite(outImage‘pp.jpg‘);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1888 2016-07-15 10:49 GetIPMImage.asv
文件 1885 2016-07-15 10:23 GetIPMImage.m
目录 0 2016-07-15 10:12 IPM\
文件 862 2016-07-15 10:43 IPM\GetVanishingPoint.m
文件 1099 2016-06-28 09:43 IPM\TransformGround2Image.m
文件 1642 2016-07-15 10:45 IPM\TransformImage2Ground.m
目录 0 2016-07-15 10:18 Images\
文件 306282 2008-10-03 11:43 Images\IMG00005.jpg
文件 190372 2008-10-03 11:43 Images\IMG00107.jpg
文件 399171 2008-10-03 11:43 Images\IMG00576.jpg
文件 429387 2008-10-03 11:43 Images\IMG00580.jpg
文件 405393 2008-10-03 11:43 Images\IMG00749.jpg
文件 353128 2008-10-03 11:43 Images\IMG00772.jpg
文件 264654 2008-10-03 11:43 Images\IMG00834.jpg
文件 265460 2008-10-03 11:43 Images\IMG00858.jpg
文件 203971 2008-10-03 11:43 Images\IMG00878.jpg
文件 238780 2008-10-03 11:43 Images\IMG00919.jpg
文件 179794 2008-10-03 11:43 Images\IMG00996.jpg
文件 228058 2008-10-03 11:43 Images\IMG01037.jpg
文件 346987 2008-10-03 11:43 Images\IMG01070.jpg
文件 288313 2008-10-03 11:43 Images\IMG01258.jpg
文件 288413 2008-10-03 11:43 Images\IMG01282.jpg
文件 229884 2008-10-03 11:43 Images\IMG01294.jpg
文件 230317 2008-10-03 11:43 Images\IMG01355.jpg
文件 255081 2008-10-03 11:43 Images\IMG01360.jpg
文件 273510 2008-10-03 11:43 Images\IMG01362.jpg
文件 213530 2008-10-03 11:43 Images\IMG01480.jpg
文件 224899 2008-10-03 11:43 Images\IMG01513.jpg
文件 215267 2008-10-03 11:43 Images\IMG01771.jpg
文件 376175 2008-10-03 11:43 Images\IMG01957.jpg
文件 402251 2008-10-03 11:43 Images\IMG02123.jpg
............此处省略14个文件信息
评论
共有 条评论