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

标签 opencv coordinate-transformation

本例中点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/

相关文章:

opencv - 在树莓派3(Raspbian Stretch)上安装opencv-python

python-3.x - 使用 Python3 Pytesseract 进行实时屏幕监控

rotation - 控制一个 Sprite 的旋转,使其始终瞄准另一个 Sprite

java - 使用鼠标移动旋转 3D View - 使用固定相机

java - OpenGL ES 2.0 : From orthogonal to perspective (card flip effect)

opencv - 在 OpenCV.js 中旋转时图像自动裁剪

python - 有没有更快的方法来找到形状的周长?

python - 使用 pyopengl 获取模型矩阵

python - 如何在matplotlib中变换坐标轴

python - DICT4X4 中的 ArUco 标记检测良好,但 DICT5x5 中的检测不佳