利用matlab攝像機標定
https://www.cnblogs.com/Jessica-jie/p/6081308.html
(1)輸入影象
“Image names”鍵
Matlab的圖形視窗顯示出20幅靶標影象
(2) 提取角點
“Extract grid corners”鍵。
輸入要進行角點提取的靶標影象的編號並回車
分別在“wintx ([] = 5) =”和“winty ([] = 5) =”輸入行中輸入角點提取區域的視窗半寬m和半高n。顯示角點提取區域的視窗尺寸(2n+1)x(2m+1),例如,選擇預設時角點提取區域的視窗尺寸為11x11畫素。
Extraction of the grid corners on the images
Number(s) of image(s) to process ([] = all images) = 17
Window size for corner finder (wintx and winty):
wintx ([] = 5) = 5
winty ([] = 5) = 5
Window size = 11x11
Do you want to use the automatic square counting mechanism (0=[]=default)
or do you always want to enter the number of squares manually (1,other)? 0
//0表示自動計算棋盤格靶標選定區域內的方格行數和列數,選擇值1表示人工計算並輸入棋盤格靶標選定區域內的方格行數和列數。
Processing image 17...
Using (wintx,winty)=(5,5) - Window size = 11x11 (Note: To reset the window size, run script clearwin)
Click on the four extreme corners of the rectangular complete pattern (the first clicked corner is the origin)...//點選四個極端的角落的矩形完整的模式(第一個點選的角落是原點)…
Size of each square along the X direction: dX=100mm//沿X方向每平方大小:DX = 100mm
Size of each square along the Y direction: dY=100mm (Note: To reset the size of the squares, clear the variables dX and dY)
If the guessed grid corners (red crosses on the image) are not close to the actual corners,
it is necessary to enter an initial guess for the radial distortion factor kc (useful for subpixel detection)//如果猜到的網格角(影象上的紅色的十字架)不接近實際的角落,需要輸入徑向畸變係數Kc的初始猜測(用於亞畫素檢測)
Need of an initial guess for distortion? ([]=no, other=yes) []
需要一個初始猜測的失真?(=不,其他=是)
Corner extraction...角點提取…
done完成
(3) 內參數標定
“Calibration”鍵
一、攝像機模型:
f是攝像機焦距。針孔中的點被理解成投影中心。光軸與影象平面的交點被稱為主點。
你也許認為主點即成像儀的中心,但這意味著需要極其精度的安裝,實際上,通常中心不在光軸上。因此引入了兩個新的引數Cx和Cy,對偏移進行建模;由於單個畫素點在低價成像儀上是矩形而不是正方形,引入兩個不同的焦距fx和fy(單位為畫素),焦距fx實際上是透鏡的物理焦距長度與成像儀每個單元尺寸Sx的乘積,fy同理。
1.x=fx(X/Z)+Cx ; y=fy(Y/Z)+Cy 【影象點(x,y);物理點(X,Y,Z)】
2.q=QM ; ;
二、內參數標定給出初始化後的標定結果和優化後的標定結果。其中,對內參數的優化採用L-M梯度下降法。優化後的結果中給出的引數不確定性,是3倍的標準方差。
fc中的兩個資料分別是kx和ky,即焦距歸一化成像平面上的成像點座標到影象座標的放大係數。
cc為光軸中心點的影象座標(u0, v0),又稱為主點座標(光軸和像平面的交點),單位:畫素。
alpha_c是對應於影象座標v的攝像機的實際y軸與理想y軸之間的夾角ac,單位為弧度,預設值為0弧度。後續給出的影象軸之間的夾角為對應於影象座標u、v的攝像機的x、y軸之間的夾角,預設值為90°。
est_alpha是alpha_c是否標定的標誌位,只有est_alpha=1時對alpha_c進行標定。
kc為畸變係數kc1~kc5,kc(1)為二階徑向畸變係數kc1,kc(2)為4階徑向畸變係數kc2,kc(5)為6階徑向畸變係數kc5,kc(3)為影象座標u對應於xy項的切向畸變係數kc3,kc(4)為影象座標v對應於xy項的切向畸變係數kc4。
err為將網格角點反投影到影象空間的誤差的標準方差,單位為畫素。
在優化後的結果中,不確定性的數值越小,說明標定的精度越高。如果不確定性項的數值與結果值相比所佔比例較大,則需要重新標定。
初始化後的標定結果:
Calibration parameters after initialization:
Focal Length: fc = [ 2261.90405 2109.71287 ]
Principal point: cc = [ 319.50000 239.50000 ]
Skew: alpha_c = [ 0.00000 ] => angle of pixel = 90.00000 degrees
Distortion: kc = [ 0.00000 0.00000 0.00000 0.00000 0.00000 ]
優化後的標定結果:
17
Calibration results after optimization (with uncertainties):
Focal Length: fc = [ 1449.63020 1465.98311 ] +/- [ 400.52656 411.89609 ]
Principal point: cc = [ 319.50000 239.50000 ] +/- [ 0.00000 0.00000 ]
Skew: alpha_c = [ 0.00000 ] +/- [ 0.00000 ] => angle of pixel axes = 90.00000 +/- 0.00000 degrees
Distortion: kc = [ -0.73547 8.76011 -0.03983 -0.03329 0.00000 ] +/- [ 0.64286 18.37382 0.02206 0.00821 0.00000 ]
Pixel error: err = [ 0.39436 0.41117 ]
16
Calibration results after optimization (with uncertainties):
Focal Length: fc = [ 1057.47799 1065.08661 ] +/- [ 179.00243 182.45017 ]
Principal point: cc = [ 319.50000 239.50000 ] +/- [ 0.00000 0.00000 ]
Skew: alpha_c = [ 0.00000 ] +/- [ 0.00000 ] => angle of pixel axes = 90.00000 +/- 0.00000 degrees
Distortion: kc = [ -0.42145 2.71172 -0.02680 -0.02733 0.00000 ] +/- [ 0.27931 4.47689 0.01235 0.00609 0.00000 ]
Pixel error: err = [ 0.39060 0.46655 ]
4
Calibration results after optimization (with uncertainties):
Focal Length: fc = [ 981.15486 990.80729 ] +/- [ 83.68588 85.72653 ]
Principal point: cc = [ 319.50000 239.50000 ] +/- [ 0.00000 0.00000 ]
Skew: alpha_c = [ 0.00000 ] +/- [ 0.00000 ] => angle of pixel axes = 90.00000 +/- 0.00000 degrees
Distortion: kc = [ -0.31958 1.45735 -0.01584 -0.02388 0.00000 ] +/- [ 0.23908 3.49317 0.00665 0.00536 0.00000 ]
Pixel error: err = [ 0.52427 0.49251 ]
(4) 顯示攝像機與標定靶標之間的關係
“Show Extrinsic”鍵
假設攝像機固定時攝像機與靶標之間的關係.
假設靶標固定時攝像機與靶標之間的關係
(5) 誤差分析
“Analyse error”鍵
利用滑鼠移動十字標尺可以選擇角點,即可在命令視窗顯示出該角點的資訊,包括該角點所屬影象、索引號、以方格為單位的座標、影象座標、反投影后的影象座標誤差、角點提取區域的視窗半寬m和半高n。
Selected image: 17
Selected point index: 22 //選擇點指數:22
Pattern coordinates (in units of (dX,dY)): (X,Y)=(0,3)//圖形座標(單位(dx,dy))
Image coordinates (in pixel): (326.27,97.25)//影象座標(畫素)
Pixel error = (0.39891,0.38640)//畫素誤差
Window size: (wintx,winty) = (5,5)
(6) 反投影到影象空間
“Project on image”鍵
出現“Number(s) of image(s) to process ([] = all images) =”時,輸入要進行反投影的靶標影象的編號並回車:
Number(s) of image(s) to show ([] = all images) = 17
Pixel error: err = [0.52427 0.49251] (all active images)
(7) 影象畸變校正
“Undistort image”鍵
Program that undistorts images
The intrinsic camera parameters are assumed to be known (previously computed)
Do you want to undistort all the calibration images ([],0) or a new image (1)? 1
內在的相機引數被假定為已知(先前計算)
你想所有的校正影象失真([ ],0)或一個新的影象(1)?
(8) 外引數標定
“Comp. Extrinsic”鍵
外引數包括:旋轉矩陣;平移向量,來描述物體的相對位置
外引數標定是在內參數已知的前提下進行的。在完成攝像機的內參數標定後,或者在命令視窗輸入攝像機的內參數後,可以對棋盤格靶標相對於攝像機的外引數進行標定。
Computation of the extrinsic parameters from an image of a pattern
The intrinsic camera parameters are assumed to be known (previously computed)
Image name (full name without extension): image17
Image format: ([]='r'='ras', 'b'='bmp', 't'='tif', 'p'='pgm', 'j'='jpg', 'm'='ppm') j
Extraction of the grid corners on the image
Window size for corner finder (wintx and winty):
wintx ([] = 5) =
winty ([] = 5) =
Window size = 11x11
Click on the four extreme corners of the rectangular complete pattern (the first clicked corner is the origin)...
Size dX of each square along the X direction ([]=30mm) = 100
Size dY of each square along the Y direction ([]=30mm) = 100
Corner extraction...
Extrinsic parameters:
Translation vector: Tc_ext = [ -286.312743 -270.910076 2017.432436 ]
Rotation vector: omc_ext = [ -2.148529 -2.100271 -0.134644 ] 旋轉向量
Rotation matrix: Rc_ext = [ 0.025055 0.999247 -0.029640
旋轉矩陣 0.987282 -0.020077 0.157706
0.156992 -0.033214 -0.987041 ]
Pixel error: err = [ 0.34478 0.42945 ]
在外引數標定結果中,Tc_ext為靶標座標系原點在攝像機座標系中的位移向量,單位為mm;omc_ext為對應於姿態矩陣的rodrigues旋轉向量;Rc_ext為旋轉矩陣;err為將網格角點反投影到影象空間的誤差的標準方差,單位為畫素。