傅里叶变换+ emgucv [英] Fourier Transform + emgucv

查看:132
本文介绍了傅里叶变换+ emgucv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这段代码是什么问题...

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

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

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....

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

I am using Visual studio 2010 with emgu cv.

推荐答案

好吧,我已经遍历了您的代码并对其进行调试,问题所在的是这里:

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

imageMat.CopyTo( GreyFourierImage );

您正在尝试将float []数组中的imageMat复制到图像float [,*]中,我敢肯定,您会发现只是不起作用,这就是程序挂起的原因.

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.

这是将cvDFT中的虚部和实部分开的代码:

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);

干杯

克里斯

这篇关于傅里叶变换+ emgucv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆