How can I remap a point after an image rotation?

后端 未结 2 418
自闭症患者
自闭症患者 2020-12-31 19:23

I have a mathematical question: let\'s suppose I rotate an image around its center by an angle of 30°, using the opencv with the following commands:

M = cv2.         


        
相关标签:
2条回答
  • 2020-12-31 20:14

    You can use transform() function to apply given transformation to arrays of points.

    cv2.transform(pointsToTransform, M)
    
    0 讨论(0)
  • 2020-12-31 20:18

    Just use matrix operation as described in Affine Transformations and inverse matrix.

    # inverse matrix of simple rotation is reversed rotation.
    M_inv = cv2.getRotationMatrix2D((100/2, 300/2),-30,1)
    
    
    # points
    points = np.array([[35.,  0.],
                       [175., 0.],
                       [105., 200.],
                       [105., 215.],
                      ])
    # add ones
    ones = np.ones(shape=(len(points), 1))
    
    points_ones = np.hstack([points, ones])
    
    # transform points
    transformed_points = M_inv.dot(points_ones.T).T
    
    0 讨论(0)
提交回复
热议问题