1.环境说明与应用说明
VS2015+opencv3.4,实际应用在MFC环境中!主要是用来做定位,利用平面靶标给机器人的工具快换提供定位信息
2.实际调用
CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
InputArray cameraMatrix, InputArray distCoeffs,
OutputArray rvec, OutputArray tvec,
bool useExtrinsicGuess = false, int flags = SOLVEPNP_ITERATIVE );
参数变量名 | 类型 | 说明 |
objectPoints | std::vector<cv::Point3d> | 特征点物理坐标 |
imagePoints | std::vector<cv::Point2d> | 特征点图像坐标 |
cameraMatrix | cv::Mat(3, 3, CV_32FC1) | 相机内参:3*3的float矩阵 |
distCoeffs | cv::Mat(1, 5, CV_32FC1) | 相机畸变参数 |
rvec | 输出的旋转向量 | |
tvec | 输出的平移向量 | |
useExtrinsicGuess | 0 | |
flags | 计算方法 |
其中重点flags参数选择选择如下所示:
enum { SOLVEPNP_ITERATIVE = 0,
SOLVEPNP_EPNP = 1, //!< EPnP: Efficient Perspective-n-Point Camera Pose Estimation @cite lepetit2009epnp
SOLVEPNP_P3P = 2, //!< Complete Solution Classification for the Perspective-Three-Point Problem
SOLVEPNP_DLS = 3, //!< A Direct Least-Squares (DLS) Method for PnP @cite hesch2011direct
SOLVEPNP_UPNP = 4, //!< Exhaustive Linearization for Robust Camera Pose and Focal Length Estimation
SOLVEPNP_AP3P = 5, //!< An Efficient Algebraic Solution to the Perspective-Three-Point Problem
SOLVEPNP_MAX_COUNT //!< Used for count
};
本文的应用主要是基于同一平面上的标准特征点,所以采用SOLVEPNP_ITERATIVE 方法。
结果直接上图:
warning:
切记,虽然Opencv的参数偏爱float类型,但是solvepnp中除了相机内参和畸变参数矩阵是用float类型外,其余的矩阵都是double类型,不然出出现计算结果不正确的情况。