コード例 #1
0
ファイル: matching.py プロジェクト: Avatarchik/brown-tycoon
 def __init__(self, contour, screen_size):
     center = [0,0]
     for pt in contour:
         center[0] += pt[0][0]
         center[1] += pt[0][1]
     self.center = [center[0] / len(contour), center[1] / len(contour)]
     # self.token = shape_similarity.contour_to_token(contour)
     self.screen_size = screen_size
     self.screen_diag = (screen_size[0] ** 2 + screen_size[1] ** 2) ** 0.5
     self.features = classify.features_from_contour(contour)
     self.area = cv2.contourArea(contour)
     self.shape_name = None
     self.contour = contour
コード例 #2
0
ファイル: matching.py プロジェクト: Avatarchik/brown-tycoon
 def __init__(self, screen_size):
     self.screen_size = screen_size
     self.screen_diag = (self.screen_size[0] ** 2 + self.screen_size[1] ** 2) ** 0.5
     
     self.named_contours = defaultdict(list)
     feature_vecs = []
     output_labels = []
     for name, contour in classify.get_named_contours():
         self.named_contours[name].append(contour)
         feature_vecs.append(classify.features_from_contour(contour))
         output_labels.append(name)
     
     # contours = [contour for _, contour in classify.get_named_contours()]
     # names = [name for name, _ in classify.get_named_contours()]
     # self.classifier = classify.create_contour_classifier(contours, names)
     self.classifier = classify.create_classifier(feature_vecs, output_labels)
     
     self.prev_descriptors = {}
     self.last_id = 0
     self.lifetimes = {} # start at 0