mischeiwiller commited on
Commit
4940b50
·
verified ·
1 Parent(s): 655ed85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -6,7 +6,30 @@ import numpy as np
6
  import matplotlib.pyplot as plt
7
  from scipy.cluster.vq import kmeans
8
 
9
- # ... (previous functions remain the same)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  def infer(image_input, dst_height: str, dst_width: str):
12
  image_in = image_input["image"]
 
6
  import matplotlib.pyplot as plt
7
  from scipy.cluster.vq import kmeans
8
 
9
+ def get_coordinates_from_mask(mask_in):
10
+ x_y = np.where(mask_in != [0,0,0,255])[:2]
11
+ x_y = np.column_stack((x_y[1], x_y[0]))
12
+ x_y = np.float32(x_y)
13
+ centroids,_ = kmeans(x_y,4)
14
+ centroids = np.int64(centroids)
15
+ return centroids
16
+
17
+ def get_top_bottom_coordinates(coords):
18
+ top_coord = min(coords, key=lambda x : x[1])
19
+ bottom_coord = max(coords, key=lambda x : x[1])
20
+ return top_coord, bottom_coord
21
+
22
+ def sort_centroids_clockwise(centroids: np.ndarray):
23
+ c_list = centroids.tolist()
24
+ c_list.sort(key = lambda y : y[0])
25
+
26
+ left_coords = c_list[:2]
27
+ right_coords = c_list[-2:]
28
+
29
+ top_left, bottom_left = get_top_bottom_coordinates(left_coords)
30
+ top_right, bottom_right = get_top_bottom_coordinates(right_coords)
31
+
32
+ return top_left, top_right, bottom_right, bottom_left
33
 
34
  def infer(image_input, dst_height: str, dst_width: str):
35
  image_in = image_input["image"]