Fourier Transform + emgucv

倾然丶 夕夏残阳落幕 提交于 2019-12-07 15:05:14

问题


Can anybody tell me what is the problem in this code...

Basically I am trying to compute the dft of the image and show it as an image on my screen.

Image<Gray, float> GreyOriginalImage = new Image<Gray, float>(strFileName);
Matrix<float> imageMat = new Matrix<float>( CvInvoke.cvGetOptimalDFTSize( GreyOriginalImage.Rows ) , CvInvoke.cvGetOptimalDFTSize( GreyOriginalImage.Cols ) );

GreyOriginalImage.CopyTo( imageMat.GetSubRect( GreyOriginalImage.ROI ) );
CvInvoke.cvDFT( imageMat , imageMat , Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD , imageMat.Rows );

GreyFourierImage = new Image<Gray, float>( imageMat.Rows , imageMat.Cols );
imageMat.CopyTo( GreyFourierImage );

ImageBox2.Image = GreyFourierImage;
imageBox2.Show();

The problem is that the code hangs up while executing and no image gets shown....

I am using Visual studio 2010 with emgu cv.


回答1:


Well I've gone over your code and debugged it the problem line is here:

imageMat.CopyTo( GreyFourierImage );

You are trying to copy imageMat which is a float[,] array to an image float[,,*] I'm sure you can figure out that this just doesn't work and is why the program hangs.

Here is the code that splits the Imaginary and Real parts from cvDFT:

Image<Gray, float> image = new Image<Gray, float>(open.FileName);
IntPtr complexImage = CvInvoke.cvCreateImage(image.Size, Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_32F, 2);

CvInvoke.cvSetZero(complexImage);  // Initialize all elements to Zero
CvInvoke.cvSetImageCOI(complexImage, 1);
CvInvoke.cvCopy(image, complexImage, IntPtr.Zero);
CvInvoke.cvSetImageCOI(complexImage, 0);

Matrix<float> dft = new Matrix<float>(image.Rows, image.Cols, 2);
CvInvoke.cvDFT(complexImage, dft, Emgu.CV.CvEnum.CV_DXT.CV_DXT_FORWARD, 0);

//The Real part of the Fourier Transform
Matrix<float> outReal = new Matrix<float>(image.Size);
//The imaginary part of the Fourier Transform
Matrix<float> outIm = new Matrix<float>(image.Size);
CvInvoke.cvSplit(dft, outReal, outIm, IntPtr.Zero, IntPtr.Zero);

//Show The Data       
CvInvoke.cvShowImage("Real", outReal);
CvInvoke.cvShowImage("Imaginary ", outIm);

Cheers,

Chris



来源:https://stackoverflow.com/questions/7628864/fourier-transform-emgucv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!