EmguCV 3.4.1中的傅立叶变换 [英] Fourier Transform in EmguCV 3.4.1

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

问题描述

以下代码未在EmguCV 3.4.1中编译。

The following code doesn't compile in EmguCV 3.4.1.

        Image<Gray, float> image = new Image<Gray, float>(path);
        IntPtr complexImage = CvInvoke.cvCreateImage(image.Size, 
Emgu.CV.CvEnum.IplDepth.IplDepth32F, 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.DxtType.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);

某些功能

cvSetZero()
cvDFT()
cvShowImage()

在此版本的EmguCV中不可用。

are not available in this version of EmguCV.

如何解决此问题?

推荐答案

从3.0版开始,EmguCV不仅适用于Mat,而且适用于Image。还有一些方法从CvInvoke移到Mat或Image或重命名了(例如:CvInvoke.cvShowImage-> CvInvoke.Imshow)。

Since version 3.0 EmguCV goes more for Mat instead of Image. Also somemethods were moved from CvInvoke to Mat or Image or were renamed (example: CvInvoke.cvShowImage --> CvInvoke.Imshow).

我也遇到了dft和尝试将代码从 openCV示例移植到c#。这就是我的工作方式(使用EmguCV 3.4.1):

I also had this problem with dft and tried to port the code from the openCV example to c#. This is what I work with (using EmguCV 3.4.1):

    var image = new Mat(path, ImreadModes.Grayscale);

    int a = CvInvoke.GetOptimalDFTSize(image.Rows);
    int b = CvInvoke.GetOptimalDFTSize(image.Cols);

    var extended = new Mat();
    CvInvoke.CopyMakeBorder(image, extended, 0, a - image.Rows, 0, b - image.Cols, BorderType.Constant, new MCvScalar(0));

    extended.ConvertTo(extended, DepthType.Cv32F);
    var vec = new VectorOfMat(extended, new Mat(extended.Size, DepthType.Cv32F, 1));
    var complex = new Mat();
    CvInvoke.Merge(vec, complex);

    CvInvoke.Dft(complex, complex, DxtType.Forward, 0);

    CvInvoke.Split(complex, vec);

    vec[0].ConvertTo(vec[0], DepthType.Cv8U);
    vec[1].ConvertTo(vec[1], DepthType.Cv8U);

    CvInvoke.Imshow("Real", vec[0]);
    CvInvoke.Imshow("Img", vec[1]);

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

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