fjenett commited on
Commit
390ad5b
1 Parent(s): 008f257

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -3
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  import cv2
 
3
 
4
  from pyAAMED import pyAAMED
5
 
@@ -12,13 +13,37 @@ def detect_ellipses(img_path):
12
  imgC = cv2.imread(img_path)
13
  imgG = cv2.cvtColor(imgC, cv2.COLOR_BGR2GRAY)
14
 
15
- aamed = pyAAMED(600, 600)
16
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  aamed.setParameters(3.1415926/3, 3.4, 0.77)
 
18
  result = aamed.run_AAMED(imgG)
 
 
19
  print(result)
20
 
21
- return [img_path, result]
22
 
23
  examples = [
24
  ["./AAMED/python/002_0038.jpg"]
 
1
  import gradio as gr
2
  import cv2
3
+ import json
4
 
5
  from pyAAMED import pyAAMED
6
 
 
13
  imgC = cv2.imread(img_path)
14
  imgG = cv2.cvtColor(imgC, cv2.COLOR_BGR2GRAY)
15
 
16
+ ammed_size = 1200
17
+
18
+ iheight, iwidth, _ = imgG.shape
19
+ imax = max(iheight, iwidth)
20
+ iscale = ammed_size / imax
21
+ is_landscape = iwidth >= iheight
22
+ if is_landscape:
23
+ iw = imax * iscale
24
+ ih = iheight * iscale
25
+ else:
26
+ iw = iwidth * iscale
27
+ ih = imax * iscale
28
+
29
+ imgG = imgG.resize(iw, ih)
30
+
31
+ if is_landscape:
32
+ ipad = (imax - iheight) / 2 * iscale
33
+ imgG = cv2.copyMakeBorder(imgG, ipad, ipad, 0, 0, cv2.BORDER_REPLICATE)
34
+ else:
35
+ ipad = (imax - iwidth) / 2 * iscale
36
+ imgG = cv2.copyMakeBorder(imgG, 0, 0, ipad, ipad, cv2.BORDER_REPLICATE)
37
+
38
+ aamed = pyAAMED(ammed_size, ammed_size)
39
  aamed.setParameters(3.1415926/3, 3.4, 0.77)
40
+
41
  result = aamed.run_AAMED(imgG)
42
+ result = result.replace(' ', ', ')
43
+ result = json.loads(result)
44
  print(result)
45
 
46
+ return [img_path, json.dumps(result)]
47
 
48
  examples = [
49
  ["./AAMED/python/002_0038.jpg"]