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.
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).
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?
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