【问题标题】:Emgu CvInvoke.CalcHist throws exception OpenCV: 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rowsEmgu CvInvoke.CalcHist 抛出异常 OpenCV: 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows
【发布时间】:2021-09-08 14:56:00
【问题描述】:

我想使用CvInvoke.CalcHist() 从灰度图像创建直方图。 由于某种原因,代码抛出了0 &lt;= _rowRange.start &amp;&amp; _rowRange.start &lt;= _rowRange.end &amp;&amp; _rowRange.end &lt;= m.rows 的异常。

我在Emgu - CalcHist _rowRange error 上看到了解决方案,但它对我不起作用。我也不明白为什么 VectorOfMat 应该在 UMat 不工作时工作。他们都是InputArrayOfArrays的实现者...

这是我的代码。任何帮助将不胜感激:

            #region Load image
            Image<Bgr, Byte> img = null;
            try
            {
                img = new Image<Bgr, byte>(imagePath);
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Image for file {0} was not loaded", imagePath));
            }
            #endregion

            #region Convert the image to grayscale
            UMat gray = new UMat();
            CvInvoke.CvtColor(img, gray, ColorConversion.Bgr2Gray);
            #endregion

            #region Calculate histogram

            Mat hist = new Mat();
            
            try
            {
                UMat v = new UMat();
                
                CvInvoke.CalcHist(gray, new int[] { 0 }, null, hist, new int[] { 256 }, new float[] { 0, 256 }, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

【问题讨论】:

    标签: opencv emgucv


    【解决方案1】:

    所以解决方案确实是使用 VectorOfUmat。 这样,CalcHist 的输入是单个单元格变量。变量是灰度图像。更正见下面的代码:

            VectorOfUMat vou = new VectorOfUMat();
            vou.Push(gray);
            Mat hist = new Mat();
            
            try
            {
                UMat v = new UMat();
                CvInvoke.CalcHist(vou, new int[] { 0 }, null, hist, new int[] { 256 }, new float[] { 0, 256 }, false);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 2021-09-03
      • 2017-10-14
      • 2011-12-26
      相关资源
      最近更新 更多