怎么找网站的后台地址,设计企业网络方案的五个步骤,网络营销师工作内容,新闻热点事件及评论操作系统#xff1a;ubuntu22.04 OpenCV版本#xff1a;OpenCV4.9 IDE:Visual Studio Code 编程语言#xff1a;C11
算法描述
计算两个2D点集之间的具有4个自由度的最优有限仿射变换。 cv::estimateAffinePartial2D 是 OpenCV 库中的一个函数#xff0c;用于计算两个二维… 操作系统ubuntu22.04 OpenCV版本OpenCV4.9 IDE:Visual Studio Code 编程语言C11
算法描述
计算两个2D点集之间的具有4个自由度的最优有限仿射变换。 cv::estimateAffinePartial2D 是 OpenCV 库中的一个函数用于计算两个二维点集之间的部分仿射变换矩阵2x3。与完整的仿射变换不同部分仿射变换仅估计旋转、平移和均匀缩放而不包括剪切变形。这使得它适用于保持平行线和平行性的情况例如处理相机的平移和旋转运动。
函数原型 cv::Mat cv::estimateAffinePartial2D
(InputArray from,InputArray to,OutputArray inliers noArray(),int method RANSAC,double ransacReprojThreshold 3,size_t maxIters 2000,double confidence 0.99,size_t refineIters 10
) 参数
参数from 第一个输入的2D点集。参数to 第二个输入的2D点集。参数inliers 输出向量指示哪些点是内点1-内点0-外点。参数method 用于计算变换的鲁棒方法。可能的方法包括 RANSAC - 基于RANSAC的鲁棒方法LMEDS - 最小中位数鲁棒方法默认方法为 RANSAC。 参数ransacReprojThreshold 在RANSAC算法中考虑一个点为内点的最大重投影误差。仅适用于RANSAC。参数maxIters 鲁棒方法的最大迭代次数。参数confidence 对估计变换的置信水平在0和1之间。通常0.95到0.99之间的值就足够了。过于接近1的值可能会显著减慢估计过程。低于0.8-0.9的值可能导致变换估计不准确。参数refineIters 精化算法Levenberg-Marquardt的最大迭代次数。传递0将禁用精化因此输出矩阵将是鲁棒方法的输出。
返回值
输出 2D 仿射变换4个自由度矩阵 2×3如果无法估计变换则返回空矩阵。 该函数估计一个具有4个自由度的最优2D仿射变换限于平移、旋转和均匀缩放的组合。使用选定的鲁棒算法进行估计。
计算出的变换随后会进一步通过Levenberg-Marquardt方法进行精化仅使用内点以进一步减少重投影误差。
估计的变换矩阵为 [ cos ( θ ) ⋅ s − sin ( θ ) ⋅ s t x sin ( θ ) ⋅ s cos ( θ ) ⋅ s t y ] \begin{bmatrix} \cos(\theta) \cdot s -\sin(\theta) \cdot s t_x \\ \sin(\theta) \cdot s \cos(\theta) \cdot s t_y \end{bmatrix} [cos(θ)⋅ssin(θ)⋅s−sin(θ)⋅scos(θ)⋅stxty]
其中 θ 是旋转角度s 是缩放因子tx 和 ty 分别是 x 轴和 y 轴上的平移量。
注释 RANSAC 方法实际上可以处理任意比例的外点但需要一个阈值来区分内点和外点。LMeDS 方法不需要任何阈值但它只有在内点超过50%的情况下才能正确工作。
代码示例 #include iostream
#include opencv2/opencv.hpp
#include vectorusing namespace cv;
using namespace std;int main()
{// 定义两组对应的2D点 (x, y) - 源点集和目标点集vector Point2f from { Point2f( 0, 0 ), Point2f( 1, 0 ), Point2f( 0, 1 ), Point2f( 1, 1 ) };vector Point2f to { Point2f( 2, 2 ), Point2f( 3, 2 ), Point2f( 2, 3 ), Point2f( 3, 3 ) };// 定义一个 Mat 来接收输出的部分仿射变换矩阵Mat affinePartialMatrix;// 定义一个 Mat 来接收内点信息vector uchar inliers;// 调用 estimateAffinePartial2D 函数affinePartialMatrix estimateAffinePartial2D( from, to, inliers );if ( !affinePartialMatrix.empty() ){cout Estimated Partial Affine Matrix:\n affinePartialMatrix endl;// 打印哪些点被认为是内点for ( size_t i 0; i inliers.size(); i ){if ( inliers[ i ] ){cout Point pair ( from[ i ] , to[ i ] ) is an inlier.\n;}else{cout Point pair ( from[ i ] , to[ i ] ) is an outlier.\n;}}}else{cout Failed to estimate partial affine transformation. endl;}return 0;
}运行结果
Estimated Partial Affine Matrix:
[1, -0, 2;0, 1, 2]
Point pair ([0, 0], [2, 2]) is an inlier.
Point pair ([1, 0], [3, 2]) is an inlier.
Point pair ([0, 1], [2, 3]) is an inlier.
Point pair ([1, 1], [3, 3]) is an inlier.
文章转载自: http://www.morning.hlyfn.cn.gov.cn.hlyfn.cn http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.rymb.cn.gov.cn.rymb.cn http://www.morning.rnqbn.cn.gov.cn.rnqbn.cn http://www.morning.rtspr.cn.gov.cn.rtspr.cn http://www.morning.zxrtt.cn.gov.cn.zxrtt.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.pqryw.cn.gov.cn.pqryw.cn http://www.morning.cfccp.cn.gov.cn.cfccp.cn http://www.morning.gmdtk.cn.gov.cn.gmdtk.cn http://www.morning.glncb.cn.gov.cn.glncb.cn http://www.morning.fgkrh.cn.gov.cn.fgkrh.cn http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn http://www.morning.jfch.cn.gov.cn.jfch.cn http://www.morning.hkpyp.cn.gov.cn.hkpyp.cn http://www.morning.bzkgn.cn.gov.cn.bzkgn.cn http://www.morning.qyqmj.cn.gov.cn.qyqmj.cn http://www.morning.hnmbq.cn.gov.cn.hnmbq.cn http://www.morning.dkmzr.cn.gov.cn.dkmzr.cn http://www.morning.tbnn.cn.gov.cn.tbnn.cn http://www.morning.mehrim.com.gov.cn.mehrim.com http://www.morning.fhkr.cn.gov.cn.fhkr.cn http://www.morning.wdlg.cn.gov.cn.wdlg.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.lphtm.cn.gov.cn.lphtm.cn http://www.morning.qbtj.cn.gov.cn.qbtj.cn http://www.morning.csnch.cn.gov.cn.csnch.cn http://www.morning.coffeedelsol.com.gov.cn.coffeedelsol.com http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.qinhuangdjy.cn.gov.cn.qinhuangdjy.cn http://www.morning.gwzfj.cn.gov.cn.gwzfj.cn http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn http://www.morning.jjsxh.cn.gov.cn.jjsxh.cn http://www.morning.kjlhb.cn.gov.cn.kjlhb.cn http://www.morning.zryf.cn.gov.cn.zryf.cn http://www.morning.ztqj.cn.gov.cn.ztqj.cn http://www.morning.plgbh.cn.gov.cn.plgbh.cn http://www.morning.bnygf.cn.gov.cn.bnygf.cn http://www.morning.zknjy.cn.gov.cn.zknjy.cn http://www.morning.wmcng.cn.gov.cn.wmcng.cn http://www.morning.cptzd.cn.gov.cn.cptzd.cn http://www.morning.jmtrq.cn.gov.cn.jmtrq.cn http://www.morning.ssmhn.cn.gov.cn.ssmhn.cn http://www.morning.xfwnk.cn.gov.cn.xfwnk.cn http://www.morning.qbpqw.cn.gov.cn.qbpqw.cn http://www.morning.nktgj.cn.gov.cn.nktgj.cn http://www.morning.jnrry.cn.gov.cn.jnrry.cn http://www.morning.jbctp.cn.gov.cn.jbctp.cn http://www.morning.bcdqf.cn.gov.cn.bcdqf.cn http://www.morning.fqpyj.cn.gov.cn.fqpyj.cn http://www.morning.yfnhg.cn.gov.cn.yfnhg.cn http://www.morning.hhpkb.cn.gov.cn.hhpkb.cn http://www.morning.lmzpk.cn.gov.cn.lmzpk.cn http://www.morning.bgygx.cn.gov.cn.bgygx.cn http://www.morning.ghzfx.cn.gov.cn.ghzfx.cn http://www.morning.qhkx.cn.gov.cn.qhkx.cn http://www.morning.wjlrw.cn.gov.cn.wjlrw.cn http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.ckcjq.cn.gov.cn.ckcjq.cn http://www.morning.fhykt.cn.gov.cn.fhykt.cn http://www.morning.qjdqj.cn.gov.cn.qjdqj.cn http://www.morning.bpmfg.cn.gov.cn.bpmfg.cn http://www.morning.wpkr.cn.gov.cn.wpkr.cn http://www.morning.gmnmh.cn.gov.cn.gmnmh.cn http://www.morning.qlrwf.cn.gov.cn.qlrwf.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.ylsxk.cn.gov.cn.ylsxk.cn http://www.morning.kpfds.cn.gov.cn.kpfds.cn http://www.morning.lgwpm.cn.gov.cn.lgwpm.cn http://www.morning.bpmz.cn.gov.cn.bpmz.cn http://www.morning.qlhwy.cn.gov.cn.qlhwy.cn http://www.morning.dydqh.cn.gov.cn.dydqh.cn http://www.morning.hqllx.cn.gov.cn.hqllx.cn http://www.morning.807yy.cn.gov.cn.807yy.cn http://www.morning.dpzcc.cn.gov.cn.dpzcc.cn http://www.morning.btcgq.cn.gov.cn.btcgq.cn http://www.morning.bdqpl.cn.gov.cn.bdqpl.cn http://www.morning.lhhdy.cn.gov.cn.lhhdy.cn http://www.morning.rzczl.cn.gov.cn.rzczl.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn