【问题标题】:calcHist OpenCV for C# error用于 C# 错误的 calcHist OpenCV
【发布时间】:2017-12-22 08:26:50
【问题描述】:

我正在尝试使用 OpenCV for C# (EmguCV) 从图像中计算直方图。

这是我的代码:

        VectorOfMat bgr_planes = new VectorOfMat();
        CvInvoke.Split(myImage, bgr_planes);

        int[] dim = new int[] { 0 };
        int[] histSize = new int[] { 256 };
        float[] range = new float[] { 0f, 255f };
        bool accumulate = false;

        Mat b_hist = new Mat();
        Mat g_hist = new Mat();
        Mat r_hist = new Mat();

        CvInvoke.CalcHist(bgr_planes, dim, new Mat(), b_hist, histSize, range, accumulate);
        CvInvoke.CalcHist(bgr_planes, dim, new Mat(), g_hist, histSize, range, accumulate);
        CvInvoke.CalcHist(bgr_planes, dim, new Mat(), r_hist, histSize, range, accumulate);`

但我没有得到数据 b_histg_histr_hist。我无法处理bgr_planes[0] 的特定频道,因为它们属于Mat 类型,并且会引发错误。

如何调整参数dimhistSizerange以获得颜色直方图?

非常感谢您的帮助!

【问题讨论】:

    标签: c# histogram emgucv opencv3.0 mat


    【解决方案1】:

    我自己解决了(当然是在发布问题之后...):

    这是我改变的:

            Mat x = bgr_planes[0];
    
            Mat[] bVals = new Mat[1] { x };
    
            VectorOfMat colorChannelB = new VectorOfMat();
    
            colorChannelB.Push(bVals);
    

    这将bgr_planes 的一个单一颜色通道分开。在VectorOfMat colorChannelB 现在只有一个颜色通道。对每个通道分别执行此操作并保留参数。

    【讨论】:

      猜你喜欢
      • 2011-10-11
      • 1970-01-01
      • 2016-03-17
      • 1970-01-01
      • 1970-01-01
      • 2015-05-05
      • 2013-02-19
      • 2017-08-02
      • 2015-11-24
      相关资源
      最近更新 更多