opencv - Calculate new coordinates of keypoints after transformation -
how new coordinates of points a
, b
in exemple after transformation m (40 degrees counter-clockwise rotation) ?
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() 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)
m
2 3 rotation matrix, need apply m points.
im_rotated_keypoints = im_rotated.copy() point in [a, b]: # convert homogenous coordinates in np array format first 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)
and should able see
Comments
Post a Comment