Emgu - CalcHist _rowRange错误

时间:2017-03-12 12:32:02

标签: c# c++ opencv emgucv

我正在尝试使用针对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

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题。在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