cv2.createShapeContextDistanceExtractor始终返回0.0
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.
固定以下更新。
更多相关文章
- X和y有不相容的形状
- 将2d数组数据视为定义形状的像素——是否可能创建内部和表面?
- [LeetCode] 244. Shortest Word Distance II 最短单词距离 II
- 自定义Button形状(圆形、椭圆)
- 根据两点经纬度计算距离和角度——java实现
- java 百度地图判断两点距离1