cv::estimateAffinePartial2D 是 OpenCV 中用来估计二维点集之间“相似变换”(不含透视、不含非均匀缩放)的核心函数,在标定、对准、左右眼配准、抖动/位移补偿里非常常见。

2️⃣ 估计的变换模型(非常重要)

estimateAffinePartial2D 估计的是:

[x′y′]=[scos⁡θ−ssin⁡θssin⁡θscos⁡θ][xy]+[txty]\begin{bmatrix} x' \\ y' \end{bmatrix} = \begin{bmatrix} s\cos\theta & -s\sin\theta \\ s\sin\theta & s\cos\theta \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} + \begin{bmatrix} t_x \\ t_y \end{bmatrix}[x′y′​]=[scosθssinθ​−ssinθscosθ​][xy​]+[tx​ty​​]

✔ 允许

  • 平移(Tx, Ty)

  • 旋转(θ)

  • 等比缩放(s)

❌ 不允许

  • 剪切(shear)

  • 非等比缩放

  • 透视

👉 对应 4 自由度

3️⃣ 与 estimateAffine2D / findHomography 的区别

函数模型自由度是否透视
estimateAffinePartial2D相似变换4❌
estimateAffine2D仿射6❌
findHomography单应8✔

经验法则:

  • 左右眼 / 模组装调 / 机械对准 → estimateAffinePartial2D

  • 存在剪切或像素比例不一致 → estimateAffine2D

  • 投影 / keystone → findHomography

6️⃣ 拆解参数(工程经验)

🔹 method

  • cv::RANSAC(强烈推荐)

  • cv::LMEDS(离群点少时)

🔹 ransacReprojThreshold

  • 像素单位

  • 显示/测量常用:

    
    

    1 ~ 3 px

🔹 refineIters

  • 迭代优化次数

  • 标定类建议 ≥ 10

7️⃣ 如何从矩阵中读出物理量(很有用)


double a = M.at<double>(0,0); double b = M.at<double>(1,0); double scale = std::sqrt(a*a + b*b); double theta = std::atan2(b, a); // 弧度 double tx = M.at<double>(0,2); double ty = M.at<double>(1,2);

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐