相機的標定的原理是一系列座標系的轉換,可以參見https://blog.csdn.net/a083614/article/details/78579163
我們需要求得的是相機的參數矩陣。下面我們藉由opencv3.4.4這個工具完成自己相機的標定工作。
可對系列圖片或者視頻操作,視頻處理的幀間隔在配置文件中設置,具體如下:
1、找到樣例工程所在的位置,類似
D:\gf_app\opencv3.4.4\opencv\sources\samples\cpp\tutorial_code\calib3d\camera_calibration,(實際可以選擇cmake編譯)。
2、這裏我們在VS2017中新建一個空項目,依次導入camera_calibration.cpp、VID5.xml、in_VID5.xml和out_camera_data.yml。
3、下面你只需要在項目的目錄下新建一個用來裝圖片的文件夾,放入你自己拍的棋盤圖片。
4、在VID5.xml中的<images></images>間替換爲你自己圖片的相對位置,可以看作是資源文件。
5、在in_VID5.xml中可以調節相關參數,像時間間隔等,這中間有指定資源來自於VID5.xml,如果你修改了文件名,一定要跟着做調整。這中間也規定了輸出文件名爲out_camera_data.yml,你也可以做修改。
6、運行程序,成功後打開輸出文件,顯示部分如下
%YAML:1.0
---
calibration_time: "Mon Dec 17 21:48:55 2018"
nr_of_frames: 8
image_width: 640
image_height: 480
board_width: 9
board_height: 6
square_size: 500.
fix_aspect_ratio: 1.
# flags: +fix_aspectRatio +fix_principal_point +zero_tangent_dist +fix_k4 +fix_k5
flags: 6158
fisheye_model: 0
camera_matrix: !!opencv-matrix
rows: 3
cols: 3
dt: d
data: [ 5.4299127390023045e+02, 0., 320., 0., 5.4299127390023045e+02,
240., 0., 0., 1. ]
distortion_coefficients: !!opencv-matrix
rows: 5
cols: 1
dt: d
data: [ -3.0214040047516655e-01, 1.5737511873207019e-01, 0., 0.,
-6.7916825935937147e-02 ]
avg_reprojection_error: 5.1804980014145152e-01
per_view_reprojection_errors: !!opencv-matrix
rows: 8
cols: 1
dt: f
data: [ 1.84249431e-01, 1.19247651e+00, 2.62380987e-01,
2.53399938e-01, 4.28940028e-01, 2.35481814e-01, 3.18152755e-01,
4.66196120e-01 ]
# a set of 6-tuples (rotation vector + translation vector) for each view
extrinsic_parameters: !!opencv-matrix
rows: 8
cols: 6
dt: d
data: [ 1.7338271341971803e-01, 3.1084850442053508e-01,
1.2871080783607101e-02, -1.1668863809785964e+03,
-2.2481166267118065e+03, 8.1370132141316635e+03,
3.9472565348531652e-01, 6.8983905898418996e-01,
-1.3465274256259494e+00, -8.7486716694920051e+02,
1.5986797949155020e+03, 7.2000675993181676e+03,
-2.6992447901332706e-01, 2.2059737313713362e-01,
3.6160708345269349e-01, -5.3158387432957034e+02,
-2.0577941293067506e+03, 6.4533622677334288e+03,
-1.0819178384751468e-01, 2.7568083174423402e-01,
1.5441318345003378e-03, -1.6915426104660214e+03,
-1.4004503576632214e+03, 6.7560145579527461e+03,
-2.6558608529044297e-01, 4.5824502670999967e-01,
1.3217888511070552e+00, 1.4341930452664440e+03,
-2.3507519490574246e+03, 6.3493969744674996e+03,
4.3941208878952365e-01, 3.1858002722924694e-01,
1.6430841492742718e+00, 3.6365571462368862e+03,
-1.3694485781686251e+03, 6.7102495855248681e+03,
2.2191956888580441e-01, 3.6966457533364833e-01,
1.8683394011534573e+00, 7.1751944762554035e+02,
-1.4992946431155397e+03, 7.8353216104997937e+03,
-5.5935356658327308e-02, 5.0434187257989582e-01,
1.7593903707382661e+00, 1.8455632420244174e+03,
-1.8058413754906433e+03, 6.3284810380009412e+03 ]
camera_matrix下的data矩陣即爲所求的相機參數。實際樣例程序的功能不止於此,它還可以根據得到的參數反過來映射求取誤差並對圖像加以矯正。這個後續用到再做深入。