ShapeMatchModes Hu-Moments

Hi,
I determine the similarity between two binary images using the function matchShapes with its internally used Hu Moments.

img1 = cv2.imread(path1, cv2.IMREAD_GRAYSCALE)
img1 = cv2.bitwise_not(img1)

img2 = cv2.imread(path2, cv2.IMREAD_GRAYSCALE)
img2 = cv2.bitwise_not(img2)

_,threshold = cv2.threshold(img1, 25, 255, cv2.THRESH_BINARY)
_,threshold2 = cv2.threshold(img2, 25, 255, cv2.THRESH_BINARY)

cv2.matchShapes(threshold, threshold2, cv2.CONTOURS_MATCH_I1, 0.0)

My question is addressed to ShapeMatchModes.
According to the documentation, the Hu moments are transfomed as follows, before the distance respectively the similarity is calculated through one ShapeMatchMode:
grafik

As far as I know, however, Hu moments can be negative. How is this solved for the logarithm, since this is not defined for negative numbers?

Thanks in advance!

1 Like

have a look at the src, it is only evaluated for positive numbers:

1 Like

Thanks for your quick reply. I got it! The absolute value of the Hu Moments is calculated above in the code (LOC 63/64).
But there is a new question. Why is there a comparison between the absolute Hu Moments and eps with 0.00001?