gpt4 book ai didi

OpenCV Homography,Transform a point,这段代码是干什么的?

转载 作者:太空宇宙 更新时间:2023-11-03 20:38:22 27 4
gpt4 key购买 nike

我正在处理由 OpenCV 计算的单应性。我目前使用这个单应性来使用下面的函数来转换点。此函数执行我需要的任务,但我不知道它实际上是如何工作的。

谁能逐行准确地解释最后 3 行代码背后的逻辑/理论,我知道这会转换 x,y 点,但我不清楚为什么会这样:

为什么Zpxpy是这样计算的,h中的元素对应什么到?

非常感谢您的评论:)

double h[9];
homography = cvMat(3, 3, CV_64F, h);
CvMat ps1 = cvMat(MAX_CALIB_POINTS/2,2,CV_32FC1, points1);
CvMat ps2 = cvMat(MAX_CALIB_POINTS/2,2,CV_32FC1, points2);

cvFindHomography(&ps1, &ps2, &homography, 0);

...

// This is the part I don't fully understand
double x = 10.0;
double y = 10.0;
double Z = 1./(h[6]*x + h[7]*y + h[8]);
px = (int)((h[0]*x + h[1]*y + h[2])*Z);
py = (int)((h[3]*x + h[4]*y + h[5])*Z);

最佳答案

cvFindHomography() 使用 homogenous coordinates 返回矩阵:

Homogeneous coordinates are ubiquitous in computer graphics because they allow common operations such as translation, rotation, scaling and perspective projection to be implemented as matrix operations

代码中发生了什么:笛卡尔点 p_origin_cartesian(x,y) 被转换为齐次坐标,然后应用 3x3 透视变换矩阵 h 并将结果转换回笛卡尔坐标 p_transformed_cartesian(px,py).

更新

详细说明:

p_origin_cartesian 转换为 p_origin_homogenous:

(x,y)  =>  (x,y,1)

做透视变换:

p_transformed_homogenous = h * p_origin_homogenous =

(h0,h1,h2) (x) (h0*x + h1*y + h2) (tx)
(h3,h4,h5) * (y) = (h3*x + h4*y + h5) = (ty)
(h6,h7,h8) (1) (h6*x + h7*y + h8) (tz)

p_transformed_homogenous 转换为 p_transformed_cartesian:

(tx,ty,tz)  =>  (tx/tz, ty/tz) 

翻译后的代码:

px = tx/tz;
py = ty/tz;
Z = 1/tz;

关于OpenCV Homography,Transform a point,这段代码是干什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9275567/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com