0

我正在尝试使用 EmguCV 检测图像的模糊度。现在我正在尝试对灰色图像进行 FFT,但我被卡住了,因为我的程序在调用CvInvoke.cvCopy. 见下文:

 _capturedFrames.ForEach(x =>
 {
    using(var gray = x.Convert<Gray, float>())
    {
       IntPtr complexImage = CvInvoke.cvCreateImage(gray.Size, IPL_DEPTH.IPL_DEPTH_32F, 2);

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

       var dft = new Matrix<float>(gray.Rows, gray.Cols, 2);
       CvInvoke.cvDFT(complexImage, dft, CV_DXT.CV_DXT_FORWARD, 0);

       double min;
       double max;
       Point minLoc;
       Point maxLoc;
       dft.MinMax(out min, out max, out minLoc, out maxLoc);

       if (max > overallMax)
       {
          overallMax = max;
          index = _capturedFrames.IndexOf(x);
       }

       CvInvoke.cvReleaseImage(ref complexImage);
    }
 });

上面代码的目的是遍历内存中的图像集合并找到最清晰图像的索引。让我们假设上面的方法有效……这是检测最清晰图像的可靠方法吗?FFT 是否可靠用于此目的?

4

1 回答 1

0

你们都想通了。请参阅下面的更正代码。注意 gray.NumberOfChannels 属性。

_capturedFrames.ForEach(x =>
 {
    using(var gray = x.Convert<Gray, float>())
    {
       IntPtr complexImage = CvInvoke.cvCreateImage(gray.Size, IPL_DEPTH.IPL_DEPTH_32F, gray.NumberOfChannels);

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

       var dft = new Matrix<float>(gray.Rows, gray.Cols, gray.NumberOfChannels);
       CvInvoke.cvDFT(complexImage, dft, CV_DXT.CV_DXT_FORWARD, 0);

       double min;
       double max;
       Point minLoc;
       Point maxLoc;
       dft.MinMax(out min, out max, out minLoc, out maxLoc);

       if (max > overallMax)
       {
          overallMax = max;
          index = _capturedFrames.IndexOf(x);
       }

       CvInvoke.cvReleaseImage(ref complexImage);
    }
 });
于 2012-09-18T16:46:59.243 回答