fffiloni commited on
Commit
85700c7
1 Parent(s): 336c832

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -21,7 +21,7 @@ def preprocess(img):
21
  cv2.imwrite("4_dilate.png", img_dilate)
22
 
23
  # Erode the dilated edges
24
- img_erode = cv2.erode(img_dilate, kernel, iterations=1.5)
25
  cv2.imwrite("5_erode.png", img_erode)
26
 
27
  return img_erode
@@ -45,12 +45,13 @@ def find_tip(points, convex_hull):
45
  def infer(image_in):
46
  img = cv2.imread(image_in)
47
 
48
- contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
49
-
 
50
 
51
- for cnt in contours:
52
  peri = cv2.arcLength(cnt, True)
53
- approx = cv2.approxPolyDP(cnt, 0.024 * peri, True)
54
  hull = cv2.convexHull(approx, returnPoints=False)
55
  sides = len(hull)
56
 
 
21
  cv2.imwrite("4_dilate.png", img_dilate)
22
 
23
  # Erode the dilated edges
24
+ img_erode = cv2.erode(img_dilate, kernel, iterations=2)
25
  cv2.imwrite("5_erode.png", img_erode)
26
 
27
  return img_erode
 
45
  def infer(image_in):
46
  img = cv2.imread(image_in)
47
 
48
+ contours, hierarchy = cv2.findContours(preprocess(img), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
49
+ # Filter out only the internal contours (contours with a parent)
50
+ internal_contours = [contour for contour, hier in zip(contours, hierarchy[0]) if hier[3] != -1]
51
 
52
+ for cnt in internal_contours:
53
  peri = cv2.arcLength(cnt, True)
54
+ approx = cv2.approxPolyDP(cnt, 0.025 * peri, True)
55
  hull = cv2.convexHull(approx, returnPoints=False)
56
  sides = len(hull)
57