2016-07-25 12 views
1

Wie erhalten Sie die neuen Koordinaten der Punkte a und b in diesem Beispiel nach einer Transformation M (40 Grad gegen den Uhrzeigersinn)?Berechnen Sie neue Koordinaten von Schlüsselpunkten nach der Transformation

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

Antwort

1

M ist ein 2 von 3 Rotationsmatrix, so brauchen Sie, es zu tun gilt M auf Ihre Punkte.

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) 

Und Sie sollten

der Lage sein,

rotated

zu sehen
Verwandte Themen