如何仅使用一个源点 [x,y] 的 cv2.warpperspective

Joã*_*tos 6 python opencv transformation computer-vision

我只遇到图像的一个点 (x, y) 的问题,并且已经计算了两个图像上的变换矩阵,计算第二个图像中的对应点 (x, y) 。如果我有一个来自源图像的像素点 [510,364] 和我已经计算的去变换矩阵:

Matrix Transform:  [[ 7.36664511e-01  3.38845039e+01  2.17700574e+03]
[-1.16261372e+00  6.30840432e+01  8.09587058e+03]
[ 4.28933532e-05  8.15551141e-03  1.00000000e+00]]
Run Code Online (Sandbox Code Playgroud)

我可以得到我的新观点:[3730,7635]

我怎样才能做到这一点?

h, status =cv2.findHomography(arraypoints_fire,arraypoints_vertical)

warped_image = cv2.warpPerspective(fire_image_open, h, (vertical_image_open.shape[1],vertical_image_open.shape[0]))
cv2.namedWindow('Warped Source Image', cv2.WINDOW_NORMAL)
cv2.imshow("Warped Source Image", warped_image)

cv2.namedWindow('Overlay', cv2.WINDOW_NORMAL)
overlay_image=cv2.addWeighted(vertical_image_open,0.3,warped_image,0.8,0)
cv2.imshow('Overlay',overlay_image)
Run Code Online (Sandbox Code Playgroud)

Mas*_*ind 1

我遇到了同样的问题并在这里找到了答案,但是在 cpp 上。根据文档,opencv warpPerspective 使用这个公式,其中

\n

src - 输入图像。

\n

dst - 大小为 dsize 且类型与 src 相同的输出图像。

\n

M - 3\xc3\x973 变换矩阵(逆)。

\n

在此输入图像描述

\n

直接点就可以使用:

\n
\n# M - transform matrix, created with cv2.perspectiveTransform\n\ndef warp_point(x: int, y: int) -> tuple[int, int]:\n    d = M[2, 0] * x + M[2, 1] * y + M[2, 2]\n\n    return (\n        int((M[0, 0] * x + M[0, 1] * y + M[0, 2]) / d), # x\n        int((M[1, 0] * x + M[1, 1] * y + M[1, 2]) / d), # y\n    )\n
Run Code Online (Sandbox Code Playgroud)\n

UPD:\n我又找到了一个答案,但是是在 python 上:D

\n

看来,我忘记了第一部分中的括号,已修复。

\n