今天看到一篇文章, 把 OpenCV 中实现标定的总体流程, 每个步骤, 调用的每个函数 都讲解清楚了, 直接带路, 张正友相机标定Opencv实现以及标定流程&&标定结果评价&&图像矫正流程解析(附标定程序和棋盘图).
以下分析, 适用于 OpenCV 3.1.0
-
以下函数源代码在 imgproc 模块找到
- cvUndistort2 , see in undistort.cpp
-
以下函数源代码在 calibration 模块找到 calibration.cpp
- cvFindExtrinsicCameraParams2
- cvProjectPoints2
cvProjectPoints2 : 三维点到相平面的重投影
//declaration
/* Projects object points to the view plane using
the specified extrinsic and intrinsic camera parameters */
CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
const CvMat* translation_vector, const CvMat* camera_matrix,
const CvMat* distortion_coeffs, CvMat* image_points,
CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
CvMat* dpddist CV_DEFAULT(NULL),
double aspect_ratio CV_DEFAULT(0));
cvUndistort2 : 去畸变校正
CVAPI(void) cvUndistort2( const CvArr* src, CvArr* dst,
const CvMat* camera_matrix,
const CvMat* distortion_coeffs,
const CvMat* new_camera_matrix CV_DEFAULT(0) );
cvFindExtrinsicCameraParams2 : 已知内参求外参
/* Finds extrinsic camera parameters from
a few known corresponding point pairs and intrinsic parameters */
CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
const CvMat* image_points,
const CvMat* camera_matrix,
const CvMat* distortion_coeffs,
CvMat* rotation_vector,
CvMat* translation_vector,
int use_extrinsic_guess CV_DEFAULT(0) );
- 计算原理
- 将空间点和图像点齐次化,得到图像点矩阵 m m m 空间点矩阵 M M M,
- 求取矩阵 M M M的平均值 M c M_c Mc