我正在尝试使用针对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上出现以下错误:



任何帮助表示赞赏。

最佳答案

我有同样的问题。在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 代替第一个 matt

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

10-12 00:47