使用 OpenCV (Emgu) 的 PGH
有人可以分享他们计算 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;
}
Could anyone share their code for calculating the PGH (Pairwise Geometric Histogram) similarity ? I need to find the most similar object from within a list of images.
I have written up the following code, but the results make no sense. I'd bet I am doing a silly error, and I am stuck.
Any 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
希望这对某人有帮助,这就是我的计算方法,我使用的是 Bhattacharya 距离,因此值越大,匹配度越低。还有其他指标,但我发现 B 距离最适合我的需求。
Hope this helps someone, here is how I worked it out, I am using Bhattacharya distance, hence the larger the value, the lower the match. There are other metrics as well, but I found B-distance best for my needs.