# Affine Transforming Coordinate Set

In OpenCV, I can affine transform an image using:

M = np.float32(...)
array_tform = cv2.warpAffine(arr, M, (cols, row))


this works if the image is represented as bitmap.

What about if the "image" is instead represented as a set of points (coordinates)? i.e. I want to perform the affine transformation on a set of points. For example, translate by (+1,+1):

{ (1, 2), (3, 4) } --> { (2, 3), (4, 5) }


Is there a way to affine transform a point set?

edit retag close merge delete

Sort by » oldest newest most voted

I think I made this question sound a lot more complicated than it is. Essentially I just want to get and then apply an affine transformation to a set of points which means multiplying the [point matrix|1] with the transform matrix.

The solution (for translation) is:

arr = np.array([[1,2], [3,4]])

dx = 1
dy = 1
M = np.int32([[1,0,dx],[0,1,dy]])

np.dot(np.c_[arr, np.ones(arr.shape[0])], M.T)

more

I did not understand what you mean ..... but this helps you ?

    s_p[0] = Point(0,0);
s_p[1] = Point(0,640);
s_p[2] = Point(480,0);
s_p[3] = Point(480,640);

if (!ex_ctrl_4)
{
d_p[0] = Point(0,0);
d_p[1] = Point(70,640);
d_p[2] = Point(480,0);
d_p[3] = Point(480,620);
}
else
{
d_p[0] = Point(0,0);
d_p[1] = Point(0,640);
d_p[2] = Point(480,0);
d_p[3] = Point(480,640);
}

/*1st-------2nd
|         |
|         |
|         |
3rd-------4th*/

transform_matrix = cv::getPerspectiveTransform(s_p, d_p);
cv::warpPerspective(dest_image01, dest_image1, transform_matrix, cv::Size(640, 480));

more

Official site

GitHub

Wiki

Documentation