import cv2 from detection.limits_maker import LimitsMaker from math import sqrt class FoodLimits(LimitsMaker): def __init__(self, img, scale, window_name): LimitsMaker.__init__(self, img, scale, window_name, "Food Setup") self.min_dist = 5 def compute(self): # TODO Improve with warp perspective self.min_dist = self.img.shape[0] for i, (x,y) in enumerate(self.limits): dist = sqrt((x - self.limits[i-1][0])**2 + (y - self.limits[i-1][1])**2) self.min_dist = dist if dist < self.min_dist else self.min_dist return self.min_dist def toJSON(self): return {'Min Food Size': self.min_dist} def help(self): print("--- " + self.name + ": Click on the {} corners of the tiniest food".format(self.max_limits))