HSV直方图箱等于零

时间:2015-09-05 19:44:23

标签: emgucv

我尝试使用以下代码创建和HSV直方图

Mat image = new Mat(file, LoadImageType.Color);
int hBins = 16;
int sBins = 16;
int vBins = 16;
RangeF hRange = new RangeF(0F, 180F); 
RangeF sRange = new RangeF(0f, 255f);
RangeF vRange = new RangeF(0f, 255f);

Image<Bgr, Byte> imageSource = new Image<Bgr, Byte>(image.Bitmap);
Image<Hsv, Byte> imageHsv = imageSource.Convert<Hsv, Byte>(); 

DenseHistogram hist = new DenseHistogram(new int[] { hBins, sBins, vBins }, new RangeF[] { hRange, sRange, vRange });
hist.Calculate<byte>(imageHsv.Split(), false, null); 

问题在于,当调用hist.GetBinValues()时,所有二进制值都为零

2 个答案:

答案 0 :(得分:1)

按通道计算直方图通道似乎给出了预期的输出:

                Mat image = new Mat(file, LoadImageType.Color);

                int hBins = 16;
                int sBins = 16;
                int vBins = 16;

                RangeF hRange = new RangeF(0F, 180F);
                RangeF sRange = new RangeF(0f, 256f);
                RangeF vRange = new RangeF(0f, 256f);

                var imageSource = image.ToImage<Bgr, Byte>();

                Image<Hsv, Byte> imageHsv = imageSource.Convert<Hsv, Byte>();
                var hsvChannels = imageHsv.Split();

                DenseHistogram hHist = new DenseHistogram(hBins, hRange);
                DenseHistogram sHist = new DenseHistogram(sBins, sRange);
                DenseHistogram vHist = new DenseHistogram(vBins, vRange);

                hHist.Calculate<byte>(new Image<Gray, Byte>[] { hsvChannels[0] }, false, null);
                sHist.Calculate<byte>(new Image<Gray, Byte>[] { hsvChannels[1] }, false, null);
                vHist.Calculate<byte>(new Image<Gray, Byte>[] { hsvChannels[2] }, false, null);

                var hVals = hHist.GetBinValues();
                var sVals = sHist.GetBinValues();
                var vVals = vHist.GetBinValues();.

我无法回答为什么你的方法不起作用。我看到GetBinValues()返回一个16 ^ 3值的数组,我希望它是16 * 3的值。

答案 1 :(得分:0)

在与此斗争了几天后,我抛弃了EMGU,刚从c ++中使用了OpenCV,这给了我正确的HSV箱。