I tried to compare two images and use the Hu moment to compare the outline extracted from these images: https://docs.google.com/file/d/0ByS6Z5WRz-h2WHEzNnJucDlRR2s/edit and https://docs.google.com/file / d / 0ByS6Z5WRz-h2VnZyVWRRWEFva0k / edit The second image is equal to the first, it just rotated, and I expected the result to be the same as that of Humoments. They are a little different.
The sign of humutes on the right (first image):
[[ 6.82589151e-01] [ 2.06816713e-01] [ 1.09088295e-01] [ 5.30020870e-03] [ -5.85888607e-05] [ -6.85171823e-04] [ -1.13181280e-04]]
The sign of humutes on the right (second image):
[[ 6.71793060e-01] [ 1.97521128e-01] [ 9.15619847e-02] [ 9.60179567e-03] [ -2.44655863e-04] [ -2.68791106e-03] [ -1.45592441e-04]]
In this video: http://www.youtube.com/watch?v=O-hCEXi3ymU in the fourth round I watched how he got exactly the same. Where am I wrong?
Here is my code:
nomeimg = "Sassatelli 1984 ruotato.jpg" #nomeimg = "Sassatelli 1984 n. 165 mod1.jpg" img = cv2.imread(nomeimg) gray = cv2.imread(nomeimg,0) ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) element = cv2.getStructuringElement(cv2.MORPH_CROSS,(4,4)) imgbnbin = thresh imgbnbin = cv2.dilate(imgbnbin, element) #find contour contours,hierarchy=cv2.findContours(imgbnbin,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) #Elimination small contours Areacontours = list() area = cv2.contourArea(contours[i]) if (area > 90 ): Areacontours.append(contours[i]) contours = Areacontours print('found objects') print(len(contours)) #contorus[3] for sing in first image #contours[0] for sign in second image print("humoments") mom = cv2.moments(contours[0]) Humoments = cv2.HuMoments(mom) print(Humoments)
source share