16,021,417 members

See more:

Hello

I'm trying perspective transformation of an image using homography matrix.

Given translation and rotation, I made a homography matrix and applied to the perspective transformation as:

Rotations by z-axis (any value at "psi") work alright.

But when I put any value (even 1.0 deg) to "the" or "phi", the resultant image is awkward. I cannot recognize what it is.

And when I put [-500, -500, 0] to T (translation), it produces shifted image as if it is taken in different position (shifted in right direction), but I think -500 -500 are too big. For d = 1.0, the resultant image just shows few pixel shift (not recognizably).

I thought my implementation of constructing homography matrix is right, but the results are awkward.

Could you give me some advice on this?

Thank you.

I'm trying perspective transformation of an image using homography matrix.

Given translation and rotation, I made a homography matrix and applied to the perspective transformation as:

C++

Mat srcImg = imread("tests/image3.jp2", IMREAD_COLOR); Mat dstImg, H; Get_Homography(H, srcImg.size()); warpPerspective(srcImg, dstImg, H, dstImg.size()); imshow("output", dstImg);

C++

#define FL_x 1000.0 #define FL_y 1000.0 void Get_Homography(Mat &H_out, cv::Size size) { static float H_uc[9], C[9], C_inv[9], H[9], C_inv_H_uc[9]; static float H33[3][3]; static float R[9]; static float T[3]; static float n[3]; static float d; static float nTd[9]; static float phi, the, psi; n[0] = n[1] = 0.0; n[2] = -1.0; T[0] = -500; T[1] = -500; T[2] = 0.0; d = 100.0; phi = 0.0*D2R; the = 0.0*D2R; psi = 0.0*D2R; matMult(T, n, 3, 1, 3, nTd); matMult(nTd, &d, 9, 1, 1, nTd); getDCM_I2B(phi, the, psi, R); matAdd(R, nTd, 3, 3, H_uc); C[0] = FL_x; C[1] = 0.0; C[2] = size.width / 2.0; C[3] = 0.0; C[4] = FL_y; C[5] = size.height / 2.0; C[6] = 0.0; C[7] = 0.0; C[8] = 1.0; matInv33(C, C_inv); matMult(C_inv, H_uc, 3, 3, 3, C_inv_H_uc); matMult(C_inv_H_uc, C, 3, 3, 3, H); H33[0][0] = H[0]; H33[0][1] = H[1]; H33[0][2] = H[2]; H33[1][0] = H[3]; H33[1][1] = H[4]; H33[1][2] = H[5]; H33[2][0] = H[6]; H33[2][1] = H[7]; H33[2][2] = H[8]; H_out = Mat(3, 3, CV_32F, H33); return; }

Rotations by z-axis (any value at "psi") work alright.

But when I put any value (even 1.0 deg) to "the" or "phi", the resultant image is awkward. I cannot recognize what it is.

And when I put [-500, -500, 0] to T (translation), it produces shifted image as if it is taken in different position (shifted in right direction), but I think -500 -500 are too big. For d = 1.0, the resultant image just shows few pixel shift (not recognizably).

I thought my implementation of constructing homography matrix is right, but the results are awkward.

Could you give me some advice on this?

Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject,
20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8
+1 (416) 849-8900