【问题标题】:PGH using OpenCV (Emgu)使用 OpenCV (Emgu) 的 PGH
【发布时间】:2012-03-02 03:49:23
【问题描述】:

谁能分享他们计算 PGH(成对几何直方图)相似度的代码?我需要从图像列表中找到最相似的对象。

我已经编写了以下代码,但结果毫无意义。我敢打赌我犯了一个愚蠢的错误,我被卡住了。

有什么建议吗?

 public double GetBestPGHMatch(Contour<Point> currContour, List<Contour<Point>> ContoursList)
    {
        double match = -1.0d;
        DenseHistogram histCurrContour = new DenseHistogram(
                                                       new int[2]
                                                                {
                                                                    currContour.Total,
                                                                    currContour.Total,
                                                                },
                                                        new RangeF[2]
                                                                {
                                                                    new RangeF(0, 100),
                                                                    new RangeF(0, 100)
                                                                }
                                                   );

        CvInvoke.cvCalcPGH(currContour.Ptr, histCurrContour.Ptr);
        foreach (Contour<Point> contour in ContoursList)
        {
            DenseHistogram hist = new DenseHistogram(
                                              new int[2]
                                                                {
                                                                    currContour.Total,
                                                                    currContour.Total,
                                                                },
                                                new RangeF[2]
                                                                {
                                                                    new RangeF(0, 100),
                                                                    new RangeF(0, 100)
                                                                }
                                          );

            CvInvoke.cvCalcPGH(contour.Ptr, hist.Ptr);
            double c = CvInvoke.cvCompareHist(histCurrContour.Ptr, hist.Ptr, Emgu.CV.CvEnum.HISTOGRAM_COMP_METHOD.CV_COMP_CORREL);
            if (c > match) match = c;
        }

        return match;
    }

【问题讨论】:

    标签: opencv emgucv


    【解决方案1】:

    希望这对某人有所帮助,这是我的计算方法,我使用的是 Bhattacharya 距离,因此值越大,匹配度越低。还有其他指标,但我发现 B 距离最适合我的需求。

     public double pghMatchShape(Contour<Point> shape1, Contour<Point> shape2)
        {
            DenseHistogram hist1 = new DenseHistogram(
               new int[2] { 8, 8 },
               new RangeF[2] { new RangeF(-180, 180), new RangeF(100, 100) });
            DenseHistogram hist2 = new DenseHistogram(
               new int[2] { 8, 8 },
               new RangeF[2] { new RangeF(-180, 180), new RangeF(100, 100) });
            CvInvoke.cvCalcPGH(shape1, hist1.Ptr);
            CvInvoke.cvCalcPGH(shape2, hist2.Ptr);
            CvInvoke.cvNormalizeHist(hist1.Ptr, 100.0);
            CvInvoke.cvNormalizeHist(hist2.Ptr, 100.0);
            double corr = CvInvoke.cvCompareHist(hist1, hist2, HISTOGRAM_COMP_METHOD.CV_COMP_BHATTACHARYYA);
    
            return corr;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-08-05
      • 1970-01-01
      • 2016-10-12
      • 2017-10-22
      • 1970-01-01
      • 2011-04-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多