Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am new in opencv. After completing Fourier transform, i have also got display the angle.I want to show in my window how many degree it is.please give me some idea.
C++
// crop the spectrum, if it has an odd number of rows or columns
     int m = getOptimalDFTSize( canny_image.rows );
    int n = getOptimalDFTSize( canny_image.cols ); // on the border add zero values
    copyMakeBorder(canny_image, padded, 0, m - canny_image.rows, 0, n - canny_image.cols, BORDER_CONSTANT, Scalar::all(0));

    Mat planes[2] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
    Mat complexcanny_image;
    merge(planes, 2, complexcanny_image);         // Add to the expanded another plane with zeros
	
    dft(complexcanny_image, complexcanny_image);            // this way the result may fit in the source matrix
	
    // compute the magnitude and switch to logarithmic scale
    // => log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2))
    split(complexcanny_image, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
    magnitude(planes[0], planes[1], canny_image);// planes[0] = magnitude
    //Mat canny_image = planes[0];
	
    canny_image += Scalar::all(1);                    // switch to logarithmic scale
    log(canny_image,canny_image);
	
    // crop the spectrum, if it has an odd number of rows or columns
    canny_image = canny_image(Rect(0, 0, canny_image.cols & -2, canny_image.rows & -2));


 // rearrange the quadrants of Fourier image  so that the origin is at the image center
    int cx = canny_image.cols/2;
    int cy = canny_image.rows/2;

    Mat q0(canny_image, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
    Mat q1(canny_image, Rect(cx, 0, cx, cy));  // Top-Right
    Mat q2(canny_image, Rect(0, cy, cx, cy));  // Bottom-Left
    Mat q3(canny_image, Rect(cx, cy, cx, cy)); // Bottom-Right

    Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);
	
    q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
    q2.copyTo(q1);
    tmp.copyTo(q2);

    normalize(canny_image, canny_image, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
                                         
													// viewable image form (float between values 0 and 1).

	
 imshow("spectrum magnitude", canny_image);
Posted
Updated 6-Jun-14 0:05am
v2
Comments
Sergey Alexandrovich Kryukov 5-Jun-14 13:34pm    
What angle?
Fourier Transform? Where?!
—SA
[no name] 8-Jun-14 9:21am    
thanks Alexandrovich. It will show how many degree ex:45 degree or 60 degree in display.i want to show the number.

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