food_limits.py 812 B

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