gpt4 book ai didi

c# - Emgu - CalcHist _rowRange 错误

转载 作者:行者123 更新时间:2023-11-28 05:15:27 40 4
gpt4 key购买 nike

我正在尝试使用 OpenCV 的 Emgu C# 包装器为图像的反向投影创建直方图。我有以下 OpenCV C++ 代码,我正在尝试将其转换为 Emgu C#:

char* filename = (char*)"C:\\Images\\items.jpg";
Mat im = imread(filename);
if (im.empty())
return -1;

const int channels[] = { 0, 1, 2 };
const int histSize[] = { 32, 32, 32 };
const float rgbRange[] = { 0, 256 };
const float* ranges[] = { rgbRange, rgbRange, rgbRange };

Mat hist;
Mat im32fc3, backpr32f;

im.convertTo(im32fc3, CV_32FC3);
calcHist(&im32fc3, 1, channels, Mat(), hist, 3, histSize, ranges, true, false);
calcBackProject(&im32fc3, 1, channels, hist, backpr32f, ranges);

Emgu C# 转换:

string filename = @"C:\Images\items.jpg";
Mat im = CvInvoke.Imread(filename);
if (im.IsEmpty)
{
return -1;
}

int[] channels = { 0, 1, 2 };
int[] histSize = { 32, 32, 32 };
float[] ranges = { 0.0f, 256.0f, 0.0f, 256.0f, 0.0f, 256.0f };

Mat im32fc3 = new Mat();
Mat hist = new Mat();
Mat mask = new Mat();
Mat backpr32f = new Mat();

im.ConvertTo(im32fc3, Emgu.CV.CvEnum.DepthType.Cv32F);
CvInvoke.CalcHist(im32fc3, channels, mask, hist, histSize, ranges, false);
CvInvoke.CalcBackProject(im32fc3, channels, hist, backpr32f, ranges);

但是,我在 CvInvoke.CalcHist 中收到以下错误:

OpenCV: 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows

感谢任何帮助。

最佳答案

我遇到了同样的问题。在emgu VS解决方案中找到了这段代码。

        using (Util.VectorOfMat vm = new Util.VectorOfMat())
{
vm.Push(channels[i]);
float[] ranges = new float[] { minVal, maxVal };
CvInvoke.CalcHist(vm, new int[] { 0 }, null, hist, new int[] { numberOfBins }, ranges, false);
}

使用 VectorOfMat 作为第一个参数而不是 Mat

关于c# - Emgu - CalcHist _rowRange 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42747411/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com