opencv中的solvePnP和calibrateCamera有什么区别? [英] What is the difference between solvePnP and calibrateCamera in opencv?

查看:748
本文介绍了opencv中的solvePnP和calibrateCamera有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

calibrateCamera()提供rvec,tvec,distCoeff,cameraMatrix,而solvePnP()将cameraMatrix,distCoeff作为输入并提供rvec,tvec作为输出.这两个功能之间的区别是什么?

解决方案

cv::calibrateCamera(...)

该功能从校准图案的多个视图估计单眼相机的以下参数.通常知道这种图案的几何形状(即可以是棋盘):

  • 线性内在参数:以像素(基本上是比例因子)表示的焦距主要点理想情况下,该图像位于图像中心,有时在x轴和y轴之间是一个偏斜系数(但通常为零).
  • 非线性固有参数:前面提到的参数构成了线性摄像机矩阵,但是从3D摄像机到2D图像平面的转换中也存在一些非线性参数,即镜头变形.
  • 外部参数:3D世界和3D相机坐标系之间的变换矩阵.

上述参数的估计通常基于2D-3D对应关系.该算法检测图像中的某些2D点(即棋盘)以指定对应的3D对象点(已知的3D几何形状).在最简单的情况下(可以根据cv::calibrateCamera(..., int flags, ...)的标志而定)执行以下步骤:

  • 计算线性内在参数,并将非线性参数视为零.
  • 根据近似的内在函数来估计初始相机姿势(外部).这是使用cv::solvePnP(...)完成的.
  • 执行Levenberg-Marquardt优化算法,以最小化检测到的2D图像点与3D对象点的2D投影之间的重新投影误差.这是使用cv::projectPoints(...)完成的.

cv::solvePnP(...)

在这一点上,我也隐式地回答了cv::solvePnP(...)的角色,因为这是cv::calibrateCamera(...)的一部分. 一旦拥有了相机的内在特性,就可以假定它们永远不会改变(除非您改变光学或变焦).另一方面,可以更改外部特性,即您可以旋转相机或将其放置到其他位置.您应该看到在这种情况下将对象的姿势更改为相机的场景非常相似.这就是cv::solvePnP(...)的用途.

该函数估算给定的对象姿态:

  • 模型坐标系中的一组3D对象点(也可以是3D世界),
  • 他们在图像平面上的2D投影,
  • 线性和非线性固有参数.

cv::solvePnP(...)的输出作为旋转矢量(rvec)以及平移矢量(tvec)给出,该平移矢量将3D对象点从模型坐标系带到3D摄像机坐标系. >

calibrateCamera() provides rvec, tvec, distCoeff, cameraMatrix whereas solvePnP() takes cameraMatrix, distCoeff as input and provides rvec, tvec as output. What is the deifference between these two functions?

解决方案

cv::calibrateCamera(...)

The function estimates the following parameters of a monocular camera from several views of a calibration pattern. The geometry of this pattern is usually known (i.e. it can be a chessboard):

  • The linear intrinsic parameters: the focal lengths in terms of pixels (these are basically scale factors), the principal point which would be ideally in the center of the image, and sometimes a skew coefficient between the x and the y axis (but this is often zero).
  • The non-linear intrinsic parameters: the previously mentioned parameters are forming the linear camera matrix, but there are also some non-linear parameters in the tranformation from the 3D camera to the 2D image plane, i.e. the lens distortion.
  • The extrinsic parameters: the tranformation matrix between the 3D world and 3D camera coordinate systems.

The estimation of the above mentioned parameters is usually based on 2D-3D correspondences. The algorithm detects some 2D points in the image (i.e. chessboard) for what the corresponding 3D object points are specified (known 3D geometry). It performs the following steps in the simplest case (can vary on the flags of cv::calibrateCamera(..., int flags, ...)):

  • Computes the linear intrinsic parameters and considers the non-linear ones to zero.
  • Estimates the initial camera pose (extrinsics) in function of the approximated intrinsics. This is done using cv::solvePnP(...).
  • Performs the Levenberg-Marquardt optimization algorithm to minimize the re-projection error between the detected 2D image points and 2D projections of the 3D object points. This is done using cv::projectPoints(...).

cv::solvePnP(...)

At this point, I also answered implicitly the role of cv::solvePnP(...) as this is the part of cv::calibrateCamera(...). Once you have the intrinsics of a camera, you can assume that these will never change (except you change the optics or zooming). On the other hand the extrinsics can be changed, i.e. you can rotate the camera or put it to another location. You should see that the scenario of changing an object's pose to the camera is very similar in this case. And this is what the cv::solvePnP(...) is used for.

The function estimates the object pose given:

  • A set of 3D object points in a model coordinate system (can be the 3D world as well),
  • Their 2D projections on the image plane,
  • The linear and non-linear intrinsic parameters.

The output of cv::solvePnP(...) is given as a rotation vector (rvec) together with a translation vector (tvec) that bring the 3D object points from the model coordinate system to the 3D camera coordinate system.

这篇关于opencv中的solvePnP和calibrateCamera有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆