kdb8756 commited on
Commit
aa9f16d
·
1 Parent(s): 4cea91c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -22
app.py CHANGED
@@ -8,16 +8,6 @@ color_search = np.zeros((200, 200, 3), np.uint8)
8
  color_selected = np.zeros((200, 200, 3), np.uint8)
9
  hue = 0
10
 
11
- def select_color(event, x, y, flags, param):
12
- global hue
13
- B = frame[y, x][0]
14
- G = frame[y, x][1]
15
- R = frame[y, x][2]
16
- color_search[:] = (B, G, R)
17
- if event == cv2.EVENT_LBUTTONDOWN:
18
- color_selected[:] = (B, G, R)
19
- hue = hsv[y, x][0]
20
-
21
  def search_contours(mask, frame, source):
22
  contours_count = 0
23
  contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
@@ -38,16 +28,6 @@ def search_contours(mask, frame, source):
38
  cv2.putText(frame, str(pip_count), (cX - 16, cY + 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
39
  return pip_count, frame
40
 
41
- def center_crop_with_padding(image):
42
- im = Image.fromarray(image)
43
- width, height = im.size
44
- new_size = min(width, height)
45
- im = im.crop(((width - new_size) // 2, (height - new_size) // 2, (width + new_size) // 2, (height + new_size) // 2))
46
- im = im.crop((25, 25, new_size - 25, new_size - 25))
47
- im_with_border = ImageOps.expand(im, border=3, fill=(255,255,255))
48
- return np.array(im_with_border)
49
-
50
-
51
  def detect_pips_uploaded(uploaded_image, hue_threshold):
52
  if uploaded_image is None:
53
  return None
@@ -63,8 +43,6 @@ def detect_pips_uploaded(uploaded_image, hue_threshold):
63
  upper_hsv = np.array([upper_hue, 255, 255])
64
  mask = cv2.inRange(hsv, lower_hsv, upper_hsv)
65
  count, result_frame = search_contours(mask, image, source="image")
66
- #cv2.putText(result_frame, f'Total pip count is: {count}', (10, result_frame.shape[0] - 30), font, font_scale*1.015, (0, 0, 0), 2, cv2.LINE_AA)
67
- #cv2.putText(result_frame, f'Total pip count is: {count}', (10, result_frame.shape[0] - 30), font, 1, (0, 0, 255), 3, cv2.LINE_AA)
68
  cv2.putText(result_frame, f'Total pip count is: {count}', (10, result_frame.shape[0] - 30), font, 1, (0, 255, 255), 2, cv2.LINE_AA)
69
  return result_frame
70
 
@@ -84,3 +62,4 @@ iface_uploaded = gr.Interface(fn=detect_pips_uploaded,
84
  )
85
 
86
  iface_uploaded.launch()
 
 
8
  color_selected = np.zeros((200, 200, 3), np.uint8)
9
  hue = 0
10
 
 
 
 
 
 
 
 
 
 
 
11
  def search_contours(mask, frame, source):
12
  contours_count = 0
13
  contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
 
28
  cv2.putText(frame, str(pip_count), (cX - 16, cY + 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 1)
29
  return pip_count, frame
30
 
 
 
 
 
 
 
 
 
 
 
31
  def detect_pips_uploaded(uploaded_image, hue_threshold):
32
  if uploaded_image is None:
33
  return None
 
43
  upper_hsv = np.array([upper_hue, 255, 255])
44
  mask = cv2.inRange(hsv, lower_hsv, upper_hsv)
45
  count, result_frame = search_contours(mask, image, source="image")
 
 
46
  cv2.putText(result_frame, f'Total pip count is: {count}', (10, result_frame.shape[0] - 30), font, 1, (0, 255, 255), 2, cv2.LINE_AA)
47
  return result_frame
48
 
 
62
  )
63
 
64
  iface_uploaded.launch()
65
+