【发布时间】:2021-09-08 14:56:00
【问题描述】:
我想使用CvInvoke.CalcHist() 从灰度图像创建直方图。
由于某种原因,代码抛出了0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows 的异常。
我在Emgu - CalcHist _rowRange error 上看到了解决方案,但它对我不起作用。我也不明白为什么 VectorOfMat 应该在 UMat 不工作时工作。他们都是InputArrayOfArrays的实现者...
这是我的代码。任何帮助将不胜感激:
#region Load image
Image<Bgr, Byte> img = null;
try
{
img = new Image<Bgr, byte>(imagePath);
}
catch (Exception e)
{
throw new Exception(string.Format("Image for file {0} was not loaded", imagePath));
}
#endregion
#region Convert the image to grayscale
UMat gray = new UMat();
CvInvoke.CvtColor(img, gray, ColorConversion.Bgr2Gray);
#endregion
#region Calculate histogram
Mat hist = new Mat();
try
{
UMat v = new UMat();
CvInvoke.CalcHist(gray, new int[] { 0 }, null, hist, new int[] { 256 }, new float[] { 0, 256 }, false);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
【问题讨论】: