• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: Matlab
  • 标签: 相机标定  

资源简介

matlab相机标定,直接线性法,透视投影矩阵法

资源截图

代码片段和文件信息

function M=line_calibration()
tic
%imgPoint图像坐标系中的点
imgPoint=[200.5 68.6 1
200.5 85.9 1
200.5 103.3 1
200.5 120.7 1
200.4 138.1 1
200.5 155.5 1
217.8 68.5 1
217.9 85.8 1
217.9 103.2 1
217.8 120.6 1
217.8 138.1 1
217.8 155.5 1
235.2 68.5 1
235.2 85.8 1
235.3 103.2 1
235.3 120.6 1
235.2 138.1 1
235.3 155.5 1
252.5 68.4 1
252.6 85.7 1
252.6 103.1 1
252.6 120.6 1
252.6 138.2 1
252.6 155.5 1
269.9 68.3 1
269.9 85.6 1
269.9 102.9 1
270.0 120.5 1
270.0 137.9 1
270.1 155.4 1
287.3 68.2 1
287.4 85.5 1
287.4 102.8 1
287.4 120.4 1
287.5 137.8 1
287.5 155.3 1
304.7 67.9 1
304.8 85.4 1
304.8 102.7 1
304.9 120.2 1
304.8 137.8 1
305.0 155.1 1
322.3 67.7 1
322.3 85.1 1
322.4 102.5 1
322.4 120.0 1
322.4 137.5 1
322.5 154.9 1];
%世界坐标系中的点
wPoint=[193.9 138.5 1
193.9 110.8 1
193.9 83.1 1
193.9 55.4 1
193.9 27.7 1
193.9 0 1
166.2 138.5 1
166.2 110.8 1
166.2 83.1 1
166.2 55.4 1
166.2 27.7 1
166.2 0 1
138.5 138.5 1
138.5 110.8 1
138.5 83.1 1
138.5 55.4 1
138.5 27.7 1
138.5 0 1
110.8 138.5 1
110.8 110.8 1
110.8 83.1 1
110.8 55.4 1
110.8 27.7 1
110.8 0 1
83.1 138.5 1
83.1 110.8 1
83.1 83.1 1
83.1 55.4 1
83.1 27.7 1
83.1 0 1
55.4 138.5 1
55.4 110.8 1
55.4 83.1 1
55.4 55.4 1
55.4 27.7 1
55.4 0 1
27.7 138.5 1
27.7 110.8 1
27.7 83.1 1
27.7 55.4 1
27.7 27.7 1
27.7 0 1
0 138.5 1
0 110.8 1
0 83.1 1
0 55.4 1
0 27.7 1
0 0 1];
NumOfPoint = length(imgPoint);
K=zeros(2*NumOfPoint 8);
U=zeros(2*NumOfPoint 1);
%设置K
for i=1:NumOfPoint
    K(2*i-1:)=[wPoint(i1) wPoint(i2) 1 0 0 0 -1*imgPoint(i1)*wPoint(i1) -1*imgPoint(i1)*wPoint(i2)];
    K(2*i:)=[0 0 0 wPoint(i1) wPoint(i2) 1 -1*imgPoint(i2)*wPoint(i1) -1*imgPoint(i2)*wPoint(i2)];
end
%设置U
for i=1:NumOfPoint
    U(2*i-1)=imgPoint(i1);
    U(2*i)=imgPoint(i2);
end
%最小二乘法解线性方程组
m=inv(K‘*K)*K‘*U;
M=[m(1) m(2) m(3)
   m(4) m(5) m(6)
   m(7) m(8) 1.0];
%由图像点计算实际点坐标
CptwPoint=zeros(3NumOfPoint);
IM=inv(M);
CptwPoint=IM*imgPoint‘;
%normalize
for i=1:NumOfPoint
    CptwPoint(:i)=[CptwPoint(1i)/CptwPoint(3i);CptwPoint(2i)/CptwPoint(3i);1.0];
end
%画图做比较
plot(wPoint(:1) wPoint(:2)‘*b‘);
hold on;
plot(CptwPoint(1:) CptwPoint(2:)‘+g‘);
hold off;
%误差比较
cwPoint=wPoint‘;
err=zeros(3NumOfPoint);
for i=1:NumOfPoint
    err(:i)=[CptwPoint(1i)-cwPoint(1i);CptwPoint(2i)-cwPoint(2i);0];
end
a=0;
for i=1:NumOfPoint
    a=a+err(1i);
end
x_=a/48;
a=0;
for i=1:NumOfPoint
    a=a+err(2i);
end
y_=a/48;
if x_<0.000001
    x_=0;
end
if y_<0.000001
    y_=0;
end
errx=0;
for i=1:NumOfPoint
  errx=errx+(err(1i)-x_)^2;
end
errx=sqrt(errx/48);
erry=0;
for i=1:NumOfPoint
  erry=erry+(err(2i)-y_)^2;
end
erry=sqrt(erry/48);
err=[errxerry]
toc

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2819  2010-03-17 10:00  line_calibration.m

     文件       3839  2010-03-17 10:01  matrix_projection.m

     文件       3060  2010-03-17 10:09  line_distortion.m

----------- ---------  ---------- -----  ----

                 9718                    3


评论

共有 条评论