I am using openCV distance transform in python to find maximum width of line segments. When i use it for vertical lines i.e. when the width is horizontal, it works perfectly like this:
However, for nearly horizontal lines i.e. when the width is supposed to be vertical, it gives almost 10 times bigger value for an image like this :
The code i used :
output_canvas = np.zeros(image.shape, dtype=np.uint8)
cv2.drawContours(output_canvas, cnt, i, (255, 255, 255), -1)
dist = cv2.distanceTransform(output_canvas, cv2.DIST_L2, 3)
_, mv, _, mp = cv2.minMaxLoc(dist)
width=mv*2 #(half)width*2
print(width, mp) # width, pos
draw = cv2.cvtColor(output_canvas, cv2.COLOR_GRAY2BGR)
cv2.line(draw, (0, mp[1]), (output_canvas.shape[1], mp[1]), (0, 0, 200), 3, -1)
How can i make my program calculate width regardless of contour orientation ?