I want to compute a distance between two shapes using the Hausdorff distance or shape context distance measure with cv2. The shapes are simple white shapes on a black background.

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

In order to find the distance between two shapes, I find contours of each shape and then pass the contours to the following functions: ShapeDistanceExtractor::computeDistance(contours1, countours2) and HausdorffDistanceExtractor::computeDistance(contours1, countours2).

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

Can you please explain me, why during the comparison the ShapeDistanceExtractor always returns 0.0, whereas the second method gives me different results depending on the position of a character on the image?

你可以解释一下,为什么在比较期间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

1 个解决方案

#1


0

FIXED with the following update.

固定以下更新。

更多相关文章

  1. X和y有不相容的形状
  2. 将2d数组数据视为定义形状的像素——是否可能创建内部和表面?
  3. [LeetCode] 244. Shortest Word Distance II 最短单词距离 II
  4. 自定义Button形状(圆形、椭圆)
  5. 根据两点经纬度计算距离和角度——java实现
  6. java 百度地图判断两点距离1

随机推荐

  1. 最全面的CSS3鼠标滑过动画按钮集锦
  2. 【前端词典】输入 URL 到展现涉及的缓存
  3. AngularJS 日期时间选择组件(附详细使用方
  4. HTML5制作一场精美的烟花盛宴
  5. 【前端词典】11 个 CSS 知识搭配 11 个 J
  6. HTML5 3D蝴蝶飞舞动画
  7. 聊一聊加班严重时要如何自我提升
  8. 阿里对蒋凡的处理真的太重了吗?
  9. jQuery做一个漂亮的下拉框,用十几行代码就
  10. 【前端词典】8 个提高 JS 性能的方法