2012-02-09 3 views
0

Quelqu'un pourrait-il partager son code pour le calcul de la similarité PGH (Pairwise Geometric Histogram)? J'ai besoin de trouver l'objet le plus similaire dans une liste d'images.PGH utilisant OpenCV (Emgu)

J'ai écrit le code suivant, mais les résultats n'ont aucun sens. Je parie que je fais une erreur stupide, et je suis coincé.

Des suggestions?

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; 
    } 

Répondre

0

Hope this helps quelqu'un, voici comment je travaillais dehors, je me sers de la distance Bhattacharya, donc plus la valeur, plus le match. Il y a aussi d'autres paramètres, mais j'ai trouvé la distance B la meilleure pour mes besoins.

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; 
    }