1 Star 0 Fork 0

egrp1234/lens-distortion-rectification

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
getDistParamError.m 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
Burak Benligiray 提交于 2017-07-05 14:55 . initial commit
function error = getDistParamError(kParams, I, lineGroups)
params = struct('fx',1, 'fy', 1, 'cx', size(I, 2) / 2, 'cy', size(I, 1) / 2, 'k1', 0, 'k2', 0, 'k3', 0, 'p1', 0, 'p2', 0);
params.k1 = kParams(1);
params.k2 = kParams(2);
lineGroups = undistortLineGroups(lineGroups, params);
error = gradeLineGroups(lineGroups);
function lineGroups = undistortLineGroups(lineGroups, params)
for i = 1:size(lineGroups,2)
lineGroups{i} = undistortLineGroup(lineGroups{i}, params);
end
function outLineGroup = undistortLineGroup(lineGroup, params)
fx = params.fx;
fy = params.fy;
cx = params.cx;
cy = params.cy;
k1 = params.k1;
k2 = params.k2;
k3 = params.k3;
% p1 = params.p1;
% p2 = params.p2;
K = [fx 0 cx; 0 fy cy; 0 0 1];
noLines = size(lineGroup, 1);
pts = [lineGroup(:,1:2); lineGroup(:,3:4)];
% Xp = the xyz vals of points on the z plane
hpts = inv(K)*[pts(:,1) pts(:,2) ones(length(pts),1)]';
% we calculate the undistorted points with the Newton-Raphson method
x2 = hpts(1,:);
y2 = hpts(2,:);
r2 = sqrt(x2.^2 + y2.^2);
iterations = 10;
r = r2;
x = r;
y = r;
for i = 1:length(r2)
for j = 1:iterations
r(i) = r(i) - (r(i) + k1*r(i)^3 + k2*r(i)^5 - r2(i))/(1 + 3*k1*r(i)^2 + 5*k2*r(i)^4);
end
x(i) = x2(i) / (1 + k1*r(i)^2 + k2*r(i)^4);
y(i) = y2(i) / (1 + k1*r(i)^2 + k2*r(i)^4);
end
pts(:, 1) = x * fx + cx;
pts(:, 2) = y * fy + cy;
outLineGroup = [pts(1:noLines,:) pts(noLines + 1:noLines * 2, :)];
function error = gradeLineGroups(lineGroups)
noOfLineGroups = size(lineGroups,2);
groupErrors = zeros(noOfLineGroups,1);
for i = 1:noOfLineGroups
noOfLines = size(lineGroups{i}, 1);
lineErrors = [];
for j = 1:noOfLines
for k = j+1:noOfLines
lineErrors(end + 1) = angleDiffBetweenLines(lineGroups{i}(j, :), lineGroups{i}(k, :))^2;
end
end
groupErrors(i) = mean(lineErrors);
end
error = mean(groupErrors);
function angDiff = angleDiffBetweenLines(line1, line2)
ang1 = radtodeg(atan2(line1(4) - line1(2), line1(3) - line1(1)));
ang2 = radtodeg(atan2(line2(4) - line2(2), line2(3) - line2(1)));
angDiff = abs(ang1 - ang2);
if angDiff > 180
angDiff = 360 - angDiff;
end
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/egrp1234/lens-distortion-rectification.git
git@gitee.com:egrp1234/lens-distortion-rectification.git
egrp1234
lens-distortion-rectification
lens-distortion-rectification
master

搜索帮助