gpt4 book ai didi

opencv - 计算变换后关键点的新坐标

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:30 26 4
gpt4 key购买 nike

本例中点ab经过M变换(逆时针旋转40度)后如何得到新坐标?

import cv2

cap = cv2.VideoCapture("http://i.imgur.com/7G91d2im.jpg")
a, b = (100, 100), (200, 200)

if cap.isOpened():
ret, im = cap.read()
rows, cols = im.shape[:2]

im_keypoints = im.copy()
for point in [a, b]:
cv2.circle(im_keypoints, point, 6, (0, 0, 255), -1)
cv2.imwrite("im_keypoints.jpg", im_keypoints)

M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 40, 1)
im_rotated = cv2.warpAffine(im, M, (cols, rows))

cv2.imwrite("im_rotated.jpg", im_rotated)

enter image description here enter image description here

最佳答案

M 是一个 2 x 3 旋转矩阵,因此您只需将 M 应用于您的点即可。

im_rotated_keypoints = im_rotated.copy()
for point in [a, b]:
# Convert to homogenous coordinates in np array format first so that you can pre-multiply M
rotated_point = M.dot(np.array(point + (1,)))
cv.circle(im_rotated_keypoints, (int(rotated_point[0]), int(rotated_point[1])), 6, (0, 0, 255), -1)

你应该能看到

rotated

关于opencv - 计算变换后关键点的新坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572738/

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