emgu Calculate histogram with matrices

南笙酒味 提交于 2019-12-24 00:33:06

问题


I found a similar question: creating histogram using emgu cv c#
and it works well when i passed grayscaled images, but when i use the Matrix, program throws exceptions. my code:

Matrix<double> mat = new Matrix<double>(10, 10);
mat.SetRandUniform(new MCvScalar(0.0), new MCvScalar(20.0));
DenseHistogram histo = new DenseHistogram(5, new RangeF(0.0f, 20.0f));
histo.Calculate(new Matrix<double>[] { mat }, false, null);//<--throws exception here
CvInvoke.cvShowImage("Mat Histogram", histo.GetHistogramImage().Ptr);
CvInvoke.cvWaitKey(0);

and the declaration in emgu doc is:

public void Calculate<TDepth>(
    Matrix<TDepth>[] matrices,
    bool accumulate,
    Matrix<byte> mask
)
where TDepth : new()

i cant figure out what's wrong :(


回答1:


The problem you are facing off consist on a limitation in DenseHistogram class that when invoking cvCalcArrHist throws an "Unsupported format or combination of formats".

This class compute only on float and not on double.

Matrix<float> mat = new Matrix<float>(10, 10);
mat.SetRandUniform(new MCvScalar(0.0), new MCvScalar(20.0));
DenseHistogram histo = new DenseHistogram(5, new RangeF (0.0f, 20.0f));
histo.Calculate(new Matrix<float>[] { mat }, false, null); //runs fine :)

A better design should also let the user specify also ranges using generics, Range<double> instead of static RangeF class.



来源:https://stackoverflow.com/questions/12193642/emgu-calculate-histogram-with-matrices

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!