DerrylNessie commited on
Commit
944d821
1 Parent(s): 51a71a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -26
app.py CHANGED
@@ -27,26 +27,6 @@ def draw_boxes(img, bounds, color='yellow', width=2):
27
  cv.fillPoly(mask, pts, color =(255,255,255))
28
  img = cv.inpaint(img, mask, 3, cv.INPAINT_NS)
29
  return(img)
30
-
31
- def draw_mask(img, bounds):
32
- mask = np.zeros(img.shape[:2], dtype="uint8")
33
- for bound in bounds:
34
- box0, box1, box2, box3 = bound[0]
35
-
36
- x0, y0 = box0
37
- x1, y1 = box1
38
- x2, y2 = box2
39
- x3, y3 = box3
40
-
41
- x_mid0, y_mid0 = midpoint(x1, y1, x2, y2)
42
- x_mid1, y_mi1 = midpoint(x0, y0, x3, y3)
43
-
44
- thickness = int(math.sqrt((x2 - x1)**2 + (y2 - y1)**2))
45
-
46
- cv.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
47
- img = cv.inpaint(img, mask, 1, cv.INPAINT_NS)
48
-
49
- return(img)
50
 
51
  def inference(img, lang):
52
  if lang == "english":
@@ -62,14 +42,11 @@ def inference(img, lang):
62
  im = PIL.Image.open(img.name)
63
  img_array = np.array(im)
64
  img = draw_boxes(img_array, bounds)
65
- im = draw_mask(img_array, bounds)
66
  img = Image.fromarray(img, 'RGB')
67
- im = Image.fromarray(im, 'RGB')
68
  lang = ""
69
  img.save('box.jpg')
70
- im.save('result.jpg')
71
 
72
- return ['box.jpg', 'result.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
73
 
74
  title = 'Manga Image Cleaner'
75
  description = 'Image inpainting and text detection demo with the use of EasyOCR and CV2. To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to test the program.'
@@ -85,8 +62,7 @@ choices = [
85
  gr.Interface(
86
  inference,
87
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
88
- [gr.outputs.Image(type='file', label='Output'),
89
- gr.outputs.Image(type='file', label='Output'),
90
  gr.outputs.Dataframe()],
91
  title=title,
92
  description=description,
 
27
  cv.fillPoly(mask, pts, color =(255,255,255))
28
  img = cv.inpaint(img, mask, 3, cv.INPAINT_NS)
29
  return(img)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  def inference(img, lang):
32
  if lang == "english":
 
42
  im = PIL.Image.open(img.name)
43
  img_array = np.array(im)
44
  img = draw_boxes(img_array, bounds)
 
45
  img = Image.fromarray(img, 'RGB')
 
46
  lang = ""
47
  img.save('box.jpg')
 
48
 
49
+ return ['box.jpg', pd.DataFrame(bounds). iloc[: , 1:2]]
50
 
51
  title = 'Manga Image Cleaner'
52
  description = 'Image inpainting and text detection demo with the use of EasyOCR and CV2. To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to test the program.'
 
62
  gr.Interface(
63
  inference,
64
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
65
+ [gr.outputs.Image(type='file', label='Output'),
 
66
  gr.outputs.Dataframe()],
67
  title=title,
68
  description=description,