Advertisement
Javinator9889

Untitled

Jan 16th, 2019
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1.   hu_moments_list = list()
  2.   for cnt in cont:
  3.       matrix_list_cnt = list()  # []
  4.       cv2.drawContours(warp, cnt, -1, (150, 150, 200), 4)
  5.       if len(sqrContainsNum(cnt, retNumbers(contours))) != 0:
  6.           cv2.drawContours(warp, sqrContainsNum(cnt, retNumbers(contours)), -1, (150, 150, 200), 4)
  7.           # print(sqrContainsNum(cnt, retNumbers(contours)))
  8.           for cnt in sqrContainsNum(cnt, retNumbers(contours)):
  9.               M = cv2.HuMoments(cv2.moments(cnt))
  10.               matrix_list_cnt.append(M)
  11.               # print(M)
  12.           #     for moment in M:
  13.           #         matrix[cnt][moment] = M[moment]
  14.           #
  15.           #     print(matrix)
  16.       else:
  17.         matrix_list_cnt.append(None)
  18.       hu_moments_list.append(matrix_list_cnt)
  19.       cv2.imshow('kk', warp)
  20.   from pprint import pprint
  21.   pprint(hu_moments_list)
  22.  
  23.   import pickle
  24.  
  25.   with open("numero1.file", "wb") as file:  # file = open("numero1.file", "wb")
  26.     pickle.dump(hu_moments_list, file)  # hu_moments_list -> momentos del 1
  27.  
  28.   # file.close()
  29.  
  30.   with open("numero1.file", "rb") as file:  # file = open("numero1.file", "rb")
  31.     number1_moments = pickle.load(file)
  32.    
  33.   print(number1_moments)
  34.   # file.close()
  35.  
  36.   hu_moments_1 = [momentos_obtenidos]
  37.   len(numbers[1]) == 1
  38.   len(numbers[4]) == 2
  39.   len(numbers[4][0]) == 7
  40.   len(numbers[4][1]) == 7
  41.  
  42.   numbers = {1: hu_moments_1,  # hu_moments_1 = list()
  43.             2: hu_moments_2,
  44.             3: hu_moments_3,
  45.              ...,
  46.             9: hu_moments_9}
  47.  
  48.   with open("numbers", "wb") as moments_file:
  49.     pickle.dump(numbers, moments_file)
  50.    
  51.   with open("numbers", "rb") as moments_file:
  52.     moments_dict = pickle.load(moments_file)
  53.  
  54. ##############################################################################################################
  55.   numbers = {}
  56.   for i in range(1, 10):
  57.     with open("ejemplo" + i + ".jpg", "rb") as file:
  58.       nmoments = get_number_moments(file)
  59.       numbers[i] = nmoments
  60.  
  61.   with open("numbers", "wb") as moments_file:
  62.     pickle.dump(numbers, moments_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement