我正在尝试使用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是否可靠用于此目的?
答案 0 :(得分: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);
}
});