3

我想使用 cv2 的 Hausdorff 距离或形状上下文距离测量来计算两个形状之间的距离。这些形状是黑色背景上的简单白色形状。

为了找到两个形状之间的距离,我找到每个形状的轮廓,然后将轮廓传递给以下函数:ShapeDistanceExtractor::computeDistance(contours1, countours2) 和 HausdorffDistanceExtractor::computeDistance(contours1, countours2)。

您能否解释一下,为什么在比较期间 ShapeDistanceExtractor 总是返回 0.0,而第二种方法会根据图像上字符的位置给出不同的结果?

import cv2
a = cv2.imread("1.png",0);
b = cv2.imread("2.png",0);

_, ca, _ = cv2.findContours(a, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS) 
_, cb, _ = cv2.findContours(b, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS) 
print np.shape(ca[0]) , np.shape(cb[0])

hd = cv2.createHausdorffDistanceExtractor()
sd = cv2.createShapeContextDistanceExtractor()

d1 = hd.computeDistance(ca[0],cb[0])
d2 = sd.computeDistance(ca[0],cb[0])

print d1, " ", d2
4

1 回答 1

2

修复了以下更新

于 2018-02-07T07:50:51.163 回答