0%

BBK-相机内参标定

介绍BBK软件中采用的简易内参标定, 主要用于计算相机焦距

BBK使用的内参标定方法之一

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Camera.IntrinsicsCalibriton(_calibrationAgorithm.DotLeftTop,
_calibrationAgorithm.DotRightTop,
_calibrationAgorithm.DotLeftBottom,
_calibrationAgorithm.DotRightBottom,
_calibrationAgorithm.DotHorLength,
_calibrationAgorithm.DotVerLength,
_calibrationAgorithm.DotDistance);

public void IntrinsicsCalibriton(PointF LeftTop, PointF RightTop, PointF LeftBottom, PointF RightBottom, double LengthHor, double LengthVer, double Distance)
{
// 计算四点组成矩形的四条边长(单位像素)
double L1 = Math.Sqrt((RightTop.X - LeftTop.X) * (RightTop.X - LeftTop.X) + (RightTop.Y - LeftTop.Y) * (RightTop.Y - LeftTop.Y));
double L2 = Math.Sqrt((LeftBottom.X - LeftTop.X) * (LeftBottom.X - LeftTop.X) + (LeftBottom.Y - LeftTop.Y) * (LeftBottom.Y - LeftTop.Y));
double L3 = Math.Sqrt((RightBottom.X - LeftBottom.X) * (RightBottom.X - LeftBottom.X) + (RightBottom.Y - LeftBottom.Y) * (RightBottom.Y - LeftBottom.Y));
double L4 = Math.Sqrt((RightBottom.X - RightTop.X) * (RightBottom.X - RightTop.X) + (RightBottom.Y - RightTop.Y) * (RightBottom.Y - RightTop.Y));

double diffPixelX = (L1 + L3) / 2;// 图像平均横向长度(像素)
double diffPixelY = (L2 + L4) / 2;// 图像平均竖向长度(像素)

if ((diffPixelX == 0) || (diffPixelY == 0))
throw new ArgumentOutOfRangeException("boardParam.RightTop , boardParam.LeftTop , boardParam.RightBottom , boardParam.LeftBottom");

// Distance为感光芯片到物体的距离 = 光学公式中的D+f(近似认为像距=焦距)
// 即:(D-f)/f = L/p
// 下面公式中为: f = D*p / (L+p)
// f/D = p/(L+p)
// D/f = (L+p)/p = L/p + 1
// D/f-1 = L/p = (D-f)/f
double fx = (Distance * diffPixelX * PixelSize) / (LengthHor + diffPixelX * PixelSize);
double fy = (Distance * diffPixelY * PixelSize) / (LengthVer + diffPixelY * PixelSize);
// 相机焦距为XY方向的平均焦距(单位毫米)
Intrinsics_f = fx / 2 + fy / 2;
// 相机内参(单位像素)
Intrinsics_Fx = (fx / PixelSize).Round(4);
Intrinsics_Fy = (fy / PixelSize).Round(4);
// 相机内参(单位像素)
Intrinsics_Cx = PixelWidth / 2;
Intrinsics_Cy = PixelHeight / 2;
}