Ask Your Question
0

Affine Transforming Coordinate Set

asked 2015-01-21 17:05:41 -0600

AlexRothberg gravatar image

updated 2015-01-22 09:34:13 -0600

berak gravatar image

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2015-01-22 09:36:05 -0600

AlexRothberg gravatar image

updated 2015-01-22 23:17:16 -0600

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)
edit flag offensive delete link more
1

answered 2015-01-22 08:59:52 -0600

gfx gravatar image

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));
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-01-21 17:05:41 -0600

Seen: 1,672 times

Last updated: Jan 22 '15