【OpenCV】张正友标定法的 OpenCV 实现

今天看到一篇文章, 把 OpenCV 中实现标定的总体流程, 每个步骤, 调用的每个函数 都讲解清楚了, 直接带路, 张正友相机标定Opencv实现以及标定流程&&标定结果评价&&图像矫正流程解析(附标定程序和棋盘图).


文章目录

    • cvProjectPoints2 : 三维点到相平面的重投影
    • cvUndistort2 : 去畸变校正
    • cvFindExtrinsicCameraParams2 : 已知内参求外参
  • Ref

以下分析, 适用于 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) );
  • 计算原理
  1. 将空间点和图像点齐次化,得到图像点矩阵 m m m 空间点矩阵 M M M
  2. 求取矩阵 M M M的平均值 M c M_c Mc
  3. 计算另一个矩阵 m m = ( M − M c ) T ( M − M c ) mm = (M-M_c)^T(M-M_c) mm=(MMc)T(MMc)
  4. m m mm mm进行 SVD 分解, m m = U W V mm=UWV mm=UWV
  5. R t = V R_t = V Rt=V
  6. T t = − M c R t T_t = -M_cR_t Tt=McRt
  7. M x y = V t M T + T t M_{xy} = V_tM^T+T_t Mxy=VtMT+Tt
  8. H = find homography between  m  and  M x y H = \text{find homography between } m \text{ and } M_{xy} H=find homography between m and Mxy
  9. H = [ h 1 , h 2 , t ] , then normalization H = [h_1, h_2, t], \text{then normalization} H=[h1,h2,t],then normalization
  10. h 1 = h 1 ∣ h 1 ∣ h_1 = \frac {h_1}{\vert h_1 \vert} h1=h1h1
  11. t = t ∣ h 1 ∣ + ∣ h 2 ∣ t = \frac {t}{|h_1|+|h_2|} t=h1+h2t
  12. h 3 = h 1 × h 2 h_3 = h_1 \times h_2 h3=h1×h2
  13. H = [ h 1 , h 2 , h 3 ] H = [h_1, h_2, h_3] H=[h1,h2,h3]
  14. final result,  R f = H ∗ R t , t f = H ∗ T t + t \text{final result, }R_f = H * R_t, t_f = H*T_t + t final result, Rf=HRt,tf=HTt+t
  15. LM 迭代优化

Ref

  • OpenCV 3.1.0 Module : Camera Calibration and 3D Reconstruction
  • opencv中cvFindExtrinsicCameraParams2函数的算法原理? - 鱼丸还是粗面的回答 - 知乎 : 嗯, 讲解的很透彻了.

你可能感兴趣的:(OpenCV)