傅立叶变换+ emgucv

3 fft emgucv

任何人都能告诉我这段代码中的问题是什么......

基本上我正在尝试计算图像的dft并将其显示为我的屏幕上的图像.

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();
Run Code Online (Sandbox Code Playgroud)

问题是代码在执行时挂起,没有显示图像....

我正在使用Visual Studio 2010与emgu cv.

Chr*_*ris 5

好吧,我已经检查了你的代码并调试它问题行在这里:

imageMat.CopyTo( GreyFourierImage );
Run Code Online (Sandbox Code Playgroud)

你试图将一个float [ , ]数组的imageMat复制到一个浮动[ , ],我确定你可以发现这不起作用,这就是程序挂起的原因.

这是从cvDFT中分割Imaginary和Real部分的代码:

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);
Run Code Online (Sandbox Code Playgroud)

干杯,

克里斯