Example 6-1 ...... Example 6-5 image transformation

Source: Internet
Author: User

// Example 6-1 use cvhoughcircles to return the circle sequence found in the grayscale image <br/> // input: program name image name <br/> // output: <br/> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> <br/> # include <math. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvnamedwindow ("Lala", 1 ); <br/> iplimage * image = cvloadimage (argv [1], cv_load_image_grayscale); // load the image in grayscale format <br/> cvshowimage ("Original Image", image ); <br/> cvmemstorage * storage = cvcreatememstorage (0); // The default value of bolck_size is 0. <br/> cvsmooth (image, image, cv_gaussian, 5, 5 ); // perform Gaussian smoothing and blur Points <br/> cvshowimage ("after Gaussian 5, 5", image); <br/> cvseq * result = cvhoughcircles (image, storage, cv_hough_gradient, 2, image-> width/10); <br/> for (INT I = 0; I <result-> total; I ++) <br/>{< br/> float * P = (float *) cvgetseqelem (result, I ); <br/> cvpoint Pt = cvpoint (cvround (P [0]), cvround (P [1]); <br/> cvcircle (image, PT, cvround (P [2]), cv_rgb (0xff, 0xff, 0xff); <br/>}< br/> cvshowimage ("after the Hoff transformation", image ); <br/> cvwaitkey (0); <br/> cvreleaseimage (& image); <br/> cvdestroywindow ("Lala"); <br/> return 0; <br/>}< br/> // The running result is 6-1. JPG

 

// Example 6-2 affine transform <br/> // input: program name image <br/> // output: transformed image <br/> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvnamedwindow ("affine_transform", 1 ); <br/> cvpoint2d32f srctri [3], dsttri [3]; <br/> cvmat * rot_mat = cvcreatemat (2, 3, cv_32fc1 ); <br/> cvmat * warp_mat = cvcreatemat (2, 3, cv_32fc1); <br/> iplimage * SRC, * DST; <br/> If (argc = 2) & (src = cvloadimag E (argv [1], 1 ))! = 0) <br/>{< br/> DST = cvcloneimage (SRC); <br/> DST-> origin = Src-> origin; <br/> cvzero (DST); </P> <p> // calculate the warp matrix <br/> srctri [0]. X = 0; <br/> srctri [0]. y = 0; </P> <p> srctri [1]. X = Src-> width-1; <br/> srctri [1]. y = 0; </P> <p> srctri [2]. X = 0; <br/> srctri [2]. y = Src-> height-1; </P> <p> dsttri [0]. * = Src-> width * 0.0; <br/> dsttri [0]. y = Src-> height * 0.33; </P> <p> dsttri [1]. X = Src-> width * 0.85; <br/> dsttri [1]. y = Src-> height * 0.25; </P> <p> dsttri [2]. * = Src-> width * 0.15; <br/> dsttri [2]. y = Src-> height * 0.7; </P> <p> cvgetaffinetransform (srctri, dsttri, warp_mat); <br/> cvwarpaffine (SRC, DST, warp_mat ); <br/> cvcopy (DST, Src); </P> <p> cvpoint2d32f center = cvpoint2d32f (SRC-> width/2, Src-> height/2 ); </P> <p> double angle =-50.0; <br/> double scale = 0.6; </P> <p> cv2drotationmatrix (center, angle, scale, rot_mat ); </P> <p> // conversion <br/> cvwarpaffine (SRC, DST, rot_mat); </P> <p> cvshowimage ("affine_transform", DST ); <br/> cvwaitkey (0); <br/>}< br/> cvreleaseimage (& DST); <br/> cvreleasemat (& rot_mat ); <br/> cvreleasemat (& warp_mat); <br/> cvdestroyallwindows (); <br/> return 0; <br/>}< br/> // The program runs on: 6-2 running results. JPG <br/>

 

// Example 6-3 pivoting conversion code <br/> // input: original program name image <br/> // output: transformed image <br/> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvpoint2d32f srcquad [4], dstquad [4]; <br/> cvmat * warp_matrix = cvcreatemat (3,3, cv_32fc1); <br/> iplimage * SRC, * DST; <br/> If (argc = 2) & (src = cvloadimage (argv [1])! = 0) <br/>{< br/> DST = cvcloneimage (SRC); <br/> DST-> origin = Src-> origin; <br/> cvzero (DST); </P> <p> srcquad [0]. X = 0; <br/> srcquad [0]. y = 0; </P> <p> srcquad [1]. X = Src-> width-1; <br/> srcquad [1]. y = 0; </P> <p> srcquad [2]. X = 0; <br/> srcquad [2]. y = Src-> height-1; </P> <p> srcquad [3]. X = Src-> width-1; <br/> srcquad [3]. y = Src-> height-1; </P> <p> dstquad [0]. * = Src-> width * 0.05; <br/> dstquad [0]. y = Src-> height * 0.33; </P> <p> dstquad [1]. X = Src-> width * 0.9; <br/> dstquad [1]. y = Src-> height * 0.25; </P> <p> dstquad [2]. * = Src-> width * 0.2; <br/> dstquad [2]. y = Src-> height * 0.7; </P> <p> dstquad [3]. * = Src-> width * 0.8; <br/> dstquad [3]. y = Src-> height * 0.9; </P> <p> cvgetperspectivetransform (srcquad, dstquad, warp_matrix); </P> <p> cvwarpperspective (SRC, DST, warp_matrix); </P> <p> cvnamedwindow ("perspective_warp", 1); <br/> cvshowimage ("perspective_warp", DST ); <br/> cvwaitkey (0); <br/>}< br/> cvreleaseimage (& DST); <br/> cvdestroyallwindows (); <br/> return 0; <br/>}</P> <p> // The running result is 6-3. JPG

 

// Example 6-4 logarithm of number pole transformation <br/> // input: the program name image name is a floating point number, and the program defaults to 40 <br/> // output: transformed image </P> <p> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> <br/> # include <cxcore. h> </P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvnamedwindow ("Lala", 1 ); <br/> iplimage * src1 = cvloadimage (argv [1], 1); <br/> cvshowimage ("original image src1", src1 ); <br/> // double M = atof (argv [2]); // read as a floating point <br/> double M = 40; <br/> iplimage * DST = cvcreatei MAGE (cvgetsize (src1), 8, 3); // depth = 8, channels = 3 <br/> iplimage * src2 = cvcreateimage (cvgetsize (src1), 8, 3 ); <br/> // cvshowimage ("after src2 create", src2); // run properly, gray <br/> cvlogpolar (src1, DST, cvpoint2d32f (src1-> width/4, src1-> height/2), M, cv_inter_linear + cv_warp_fill_outliers); <br/> // input image, output image, center of transformation, scale Parameter of the amplitude, <br/> // (fill all pixels in the output image. If these vertices correspond to the outer vertices, set them to zero) + <br/> // indicates the inverse transformation of the matrix from the output image to the input image, and therefore can be directly used for pixel interpolation. Otherwise, the function looks for Inverse transformations from map_matrix) <br/> cvshowimage ("Polar number transformation, original image, 1 + 8. DST ", DST); </P> <p> cvlogpolar (src1, src2, cvpoint2d32f (src1-> width/4, src1-> height/2), m, cv_inter_linear | cv_warp_inverse_map); <br/> cvshowimage ("Polar number conversion, original image, 1 | 16. Src2 ", src2); </P> <p> cvlogpolar (DST, src2, cvpoint2d32f (src1-> width/4, src1-> height/2), m, cv_inter_linear | cv_warp_inverse_map); <br/> cvshowimage ("Polar number conversion, DST, 1 | 16. Src2 ", src2); </P> <p> cvwaitkey (0); <br/> cvreleaseimage (& src1); <br/> cvreleaseimage (& src2 ); <br/> cvreleaseimage (& DST); <br/> cvdestroywindow ("Lala"); <br/> return 0; <br/>}< br/> // conclusion: <br/> // The output image parameter format is incorrect, I spent half a day </P> <p>/* <br/> // The following is a reference example. After running, it is normal <br/> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> <br/> # include <cxcore. h> <br/> int main (INT argc, char ** argv) <br/>{< br/> iplimage * s RC; </P> <p> If (argc = 2) & (src = cvloadimage (argv [1], 1 ))! = 0) <br/>{< br/> cvnamedwindow ("Original Image", 1); <br/> cvshowimage ("Original Image", Src ); <br/> iplimage * DST = cvcreateimage (cvgetsize (SRC), 8, 3); <br/> iplimage * src2 = cvcreateimage (cvgetsize (SRC), 8, 3 ); <br/> cvlogpolar (SRC, DST, cvpoint2d32f (SRC-> width/2, Src-> height/2), 40, cv_inter_linear + cv_warp_fill_outliers ); <br/> cvlogpolar (DST, src2, cvpoint2d32f (SRC-> width/2, Src-> height/2), 40, cv_inter_linear + cv_warp_fill_outliers + cv_warp_inverse_map ); <br/> cvnamedwindow ("log-polar (polar number conversion)", 1); <br/> cvshowimage ("log-polar (polar number conversion)", DST ); <br/> cvnamedwindow ("inverse log-polar (inverse polar number transformation)", 1); <br/> cvshowimage ("inverse log-polar (inverse polar number transformation )", src2); <br/> cvwaitkey (); <br/>}< br/> return 0; <br/>}< br/> */

 

// Example 6-5 Use cvdft () to accelerate convolution (Discrete Fourier transformation) <br/> // This example is used to familiarize yourself with the process without input and fixed matrices, view the result step by step <br/> # include "stdafx. H "<br/> # include <cv. h> <br/> # include <pighgui. h> </P> <p> void printmat (cvmat * m) <br/> {<br/> printf ("/n % d * % d :", m-> rows, M-> Cols); <br/> for (INT I = 0; I <m-> rows; I ++) <br/> {<br/> printf ("/n row % d:/N", I); <br/> for (Int J = 0; j <m-> Cols; j ++) <br/>{< br/> float temp = 0; <br/> temp = cv_mat_elem (* m, float, I, j); <br/> printf ("% F", TEM P); <br/>}</P> <p> int main (INT argc, char ** argv) <br/> {<br/> cvmat * A = cvcreatemat (2, 3, cv_32fc1); // size: M1 * N1, here 2*3 <br/> float vals1 [] = {1, 2, 3, 4, 5, 6}; <br/> cvinitmatheader (A, 2, 3, cv_32fc1, vals1 ); <br/> // printmat (a); // success <br/>/* <br/> 2*3: <br/> Row 3: <br/> 1.000000 2.000000 3.000000 <br/> 1st rows: <br/> 4.000000 5.000000 6.000000 <br/> */</P> <p> cvmat * B = cvcreatemat (3,4, cv_32fc1); // size: m2 * N2, here 3*4 <br/> float vals2 [] = {7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18}; <br/> cvinitmatheader (B, 3, 4, cv_32fc1, vals2 ); <br/> // printmat (B); // success <br/>/* <br/> 3*4: <br/> Row 3: <br/> 7.000000 8.000000 9.000000 10.000000 <br/> row 1st: <br/> 11.000000 12.000000 13.000000 14.000000 <br/> row 2nd: <br/> 15.000000 16.000000 17.000000 18.000000 <br/> */</P> <p> cvmat * c = cvcreatemat (, cv_32fc1 ); // size :( A-> rows + B-> rows-1) * (a-> Cols + B-> Cols -1) Here 4*6 <br/> float vals3 [] = {, 22, };< br/> cvinitmatheader (C, cv_32fc1, vals3); <br/> // printmat (C ); // success <br/>/* <br/> 4*6: <br/> Row 3: <br/> 19.000000 20.000000 21.000000 22.000000 23.000000 24.000000 <br/> row 1st: <br/> 25.000000 26.000000 27.000000 28.000000 29.000000 30.000000 <br/> row 2nd: & lt; br/& gt; 31.000000 32.000000 33.000000 34.000000 35.00 0000 36.000000 <br/> row 3rd: <br/> 37.000000 38.000000 39.000000 40.000000 41.000000 <br/> */</P> <p> int dft_m = cvgetoptimaldftsize (a-> rows + B-> rows-1); // obtain the length of the vector and return an equal or large size value <br/> // printf ("/ndft_m = % d", dft_m ); // The result is 4 <br/> int dft_n = cvgetoptimaldftsize (a-> Cols + B-> Cols-1 ); <br/> // printf ("/ndft_n = % d", dft_n); // The result is 6 </P> <p> cvmat * dft_a = cvcreatemat (dft_m, dft_n, A-> type); // 4*6, floating point,-431602080.000000 <Br/> cvmat * dft_ B = cvcreatemat (dft_m, dft_n, B-> type); // 4*6, floating point,-431602080.000000 <br/> cvmat TMP; <br/> // printf ("here"); // declared successful </P> <p> cvgetsubrect (dft_a, & TMP, cvrect (, A-> cols, a-> rows); // returns the matrix header of the input image or the subset of the rectangle array of the matrix <br/> // arr: Input array. Submat: pointer to the matrix header of the rectangular array subset. Rect: The ROI Based on 0 coordinates. </P> <p> cvcopy (A, & TMP); <br/> // printmat (); // or the previous </P> <p> cvgetsubrect (dft_a, & TMP, cvrect (a-> cols, 0, dft_a-> Cols-a-> cols, a-> rows); <br/> // printmat (& TMP); // 2*3-431602080.000000 </P> <p> cvzero (& TMP ); <br/> // printmat (& TMP); // The value is 0 </P> <p> cvdft (dft_a, dft_a, cv_dxt_forward, A-> rows ); // cv_dxt_forward: 0 <br/> // printmat (dft_a); // I do not know the Fourier transform ...... <br/>/* <br/> 4*6: <br/> row 0th: <br/> 21.000000 4.000000-13.856405-3.000000 1.7320507.000000 <br/> row 1st: <br/> 6.000000-9.026278-7.830127-0.633975 2.3660252.000000 <br/> row 2nd: <br/>-15.000000-3.000000 5.196152 0.000000-0.000000 <br/> row 5.000000: <br/>-9.000000 10.026278-0.830127-2.366025-0.633975-3.000000 <br/> */</P> <p> cvgetsubrect (dft_ B, & TMP, cvrect, b-> cols, B-> rows); <br/> cvcopy (B, & TMP); <br/> cvgetsubrect (dft_ B, & TMP, cvrect (B-> cols, 0, dft_ B-> Cols-B-> cols, B-> rows); <br/> cvzero (& TMP ); <br/> cvdft (dft_ B, dft_ B, cv_dxt_forward, B-> rows); <br/> // printmat (dft_ B); // Fourier transformation is performed, I don't know ...... <br/>/* <br/> 4*6: <br/> Row 3: <br/> 150.000000-10.499998-64.951904 37.500000 2.598076-6.000000 <br/> row 1st: <br/>-32.000000-21.650637 17.356407-7.133974-12.499998 0.000000 <br/> row 2nd: <br/>-50.000000-3.500000-21.650633 12.500001 0.8660242.000000 <br/> row 3rd: <br/> 50.000000 21.650637 10.356408-8.866026 12.500000-2.000000 <br/> */</P> <p> cvmulspectrums (dft_a, dft_ B, dft_a, 0 ); // spectrum multiplication, A = a * B <br/> // printmat (dft_a); // do not know <br/>/* <br/> 4*6: <br/> row 0th: <br/> 3150.000000-941.999878-114.315392-117.000000 57.157654-42.000000 <br/> row 1st: <br/>-942.000000 331.327545 12.863465 34.098072-8.954475 10.000000 <br/> row 2nd: <br/> 180.000000 122.999977 46.765366-0.000000 0.0000034.000000 <br/> row 3rd: <br/>-450.000000 225.672440 85.863457-28.901924 23.954475 <br/> */</P> <p> cvdft (dft_a, dft_a, cv_dxt_inv_scale, C-> rows ); // cv_dxt_inv_scale: 3, C-> rows: 4 <br/> // printmat (dft_a ); // do not know <br/>/* <br/> 4*6: <br/> Row 3: <br/> 7.000010 22.000006 45.999996 51.999992 46.999996 30.000006 <br/> row 1st: <br/> 39.000011 101.000015 188.000000 209.000000 171.000000 102.000015 <br/> row 2nd: <br/> 59.000011 149.000015 272.000000 293.000000 235.000000 138.000000 <br/> row 3rd: <br/> 60.000000 139.000000 238.000000 253.000000 192.000000 <br/> */</P> <p> cvgetsubrect (dft_a, & TMP, cvrect (108.000000, C-> cols, c-> rows); // equivalent to copying <br/> // printmat (dft_a); <br/> cvcopy (& TMP, C ); <br/> // printmat (& TMP); // The same as dft_a <br/> // printmat (C ); // The same as dft_a </P> <p> cvreleasemat (& dft_a); <br/> cvreleasemat (& dft_ B ); </P> <p> cvwaitkey (0); <br/> return 0; <br/>}< br/>

 

Fourier transformation using images has not yet been implemented

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.