攝像頭模型採用針孔成像模型,誤差參數分三類:
讀取棋盤格影片或多張圖片。
// 找角點
cvFindChessboardCorners(image, pattern_size, corners, &corner_count,
CV_CALIB_CB_ADAPTIVE_THRESH + CV_CALIB_CB_NORMALIZE_IMAGE);
// 亞像素精度優化
cvFindCornerSubPix(image, corners, count, win, zero_zone, criteria);
參數說明:pattern_size 為每行列內角點數;flags 控制自適應閾值、亮度均衡化、四邊形過濾等。
cvCalibrateCamera2(object_points, image_points, point_counts, image_size,
intrinsic_matrix, distortion_coeffs, rotation_vectors, translation_vectors, flags);
object_points:世界座標系中的棋盤格角點位置(3D)。image_points:影像平面上偵測到的角點座標(2D)。flags:可固定主點、長寬比、切向畸變為零等約束條件。兩種方法:
cvInitUndistortMap(intrinsic_matrix, distortion_coeffs, mapx, mapy);
cvRemap(src, dst, mapx, mapy, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS);
預先計算映射表,重複校正時直接套用,避免重複計算。cvUndistort2(src, dst, camera_matrix, distortion_coeffs, new_camera_matrix);
簡便但每次皆重算映射,效率較低。
完整程式碼可參考 OpenCV 官方範例
calibration.cpp,本文重點在流程與參數解析。如需原始碼請留言聯繫。