The Perspective transform and the affine transform have the same characteristics. We have mentioned the radiation change. Here we will compare it with the perspective transform again.
1 # include "CV. H "2 # include" highgui. H "3 using namespace CV; 4 void warpperspective (iplimage * IMG); 5 void warpfangshe (iplimage * IMG); 6 int main () 7 {8 iplimage * getimg = cvloadimage ("E:/picture/wife2.jpg"); 9 iplimage * IMG = cvcreateimage (cvsize (350,450), getimg-> depth, getimg-> nchannels); 10 cvresize (getimg, IMG); 11 warpperspective (IMG); 12 // warpfangshe (IMG); 13 cvwaitkey (); 14 cvdestroyallwindows (); 15 return 0; 16} 17 // perspective transformation 18 // transformation of any quadrilateral 19 // four points required for perspective transformation 20 void warpperspective (iplimage * IMG) 21 {22 iplimage * DST = cvcreateimage (cvgetsize (IMG), IMG-> depth, IMG-> nchannels); 23 cvmat * MAT = cvcreatemat (3,3, cv_32fc1 ); 24 cvpoint2d32f ori_point [4], dst_point [4]; 25 ori_point [0]. X = 0; ori_point [0]. y = 0; 26 ori_point [1]. X = IMG-> width-1; ori_point [1]. y = 0; 27 ori_point [2]. X = 0; ori_point [2]. y = IMG-> height-1; 28 ori_point [3]. X = IMG-> width-1; ori_point [3]. y = IMG-> height-1; 29 dst_point [0]. X = IMG-> width/2; dst_point [0]. y = IMG-> height * 0.05; 30 dst_point [1]. X = IMG-> width * 0.3; dst_point [1]. y = IMG-> height/2; 31 dst_point [2]. X = IMG-> width * 0.7; dst_point [2]. y = IMG-> height/2; 32 dst_point [3]. X = IMG-> width/2; dst_point [3]. y = IMG-> height * 0.9; 33 // obtain the ing matrix 34 cvgetperspectivetransform (ori_point, dst_point, mat); 35 cvwarpperspective (IMG, DST, mat ); 36 // cvflip (DST, DST, 1); 37 cvnamedwindow ("Origin"); 38 cvnamedwindow ("warp"); 39 cvshowimage ("Origin", IMG ); 40 cvshowimage ("warp", DST); 41 cvreleaseimage (& IMG); 42 cvreleaseimage (& DST); 43 cvreleasemat (& mat ); 44} 45 void warpfangshe (iplimage * IMG) // ry transform 46 {47 // defines two cvpoint2d32f arrays 48 // The first array is used to calibrate the region 49 in the original image to be transformed // The second array is used to calibrate the transformed position of the image in the window 50 cvpoint2d32f srctri [3], dsttri [3]; 51 // defines the ing matrix, and then calculates (2*3 matrix) 52 cvmat * warp_mat = cvcreatemat (2, 3, cv_32fc1 ); 53 cvmat * rot_mat = cvcreatemat (2, 3, cv_32fc1); 54 iplimage * SRC, * DST; 55 src = IMG; 56 DST = cvcloneimage (SRC ); 57 srctri [0]. X = 0; srctri [0]. y = 0; 58 srctri [1]. X = Src-> width-1; srctri [1]. y = 0; 59 srctri [2]. X = 0; srctri [2]. y = Src-> height-1; 60 dsttri [0]. X = 0; dsttri [0]. y = Src-> height * 0.33; 61 dsttri [1]. X = Src-> width * 0.85; dsttri [1]. y = Src-> height * 0.25; 62 dsttri [2]. X = Src-> width * 0.15; dsttri [2]. y = Src-> height * 0.7; 63 // obtain the ing matrix 64 cvgetaffinetransform (srctri, dsttri, warp_mat); 65 // ing transformation 66 cvwarpaffine (SRC, DST, warp_mat ); 67 cvcopy (DST, IMG); 68 cvnamedwindow ("warp"); 69 // cvshowimage ("warp", DST ); 70 // The following is a further rotation of the transformed image 71 cvpoint2d32f center = cvpoint2d32f (SRC-> width/2, Src-> height/2); 72 double angle = 50.0; 73 double scaling = 0.8; 74 // rotate the image 75 // The center above is the center of rotation 76 // The second and third parameters of the following functions provide the Rotation Angle and scaling scale 77 // The last parameter is output ing matrix 78/* cv2drotationmatrix (79 cvpoint2d32f center80 double angle81 double scale82 cvmat * map_matrix83) */84 cv2drotationmatrix (center, angle, scale, rot_mat); 85 cvwarpaffine (SRC, DST, rot_mat); 86 cvshowimage ("warp", DST ); 87 cvreleaseimage (& IMG); 88 cvreleaseimage (& DST); 89}
Opencv learning-perspective changes