DerrylNessie commited on
Commit
c0d4465
1 Parent(s): 3f86f95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -19,19 +19,11 @@ def draw_boxes(img, bounds, color='yellow', width=2):
19
  draw = ImageDraw.Draw(img, "RGBA")
20
  for bound in bounds:
21
  p0, p1, p2, p3 = bound[0]
22
-
23
- #for masking the image
24
- """
25
- x_mid0, y_mid0 = midpoint(x1, y1, x2, y2)
26
- x_mid1, y_mi1 = midpoint(x0, y0, x3, y3)
27
- thickness = int(math.sqrt( (x2 - x1)**2 + (y2 - y1)**2))
28
-
29
- mask = np.zeros(img.shape[:2], dtype="uint8")
30
- cv2.line(mask, (x_mid0, y_mid0), (x_mid1, y_mi1), 255, thickness)
31
- masked = cv2.bitwise_and(img, img, mask=mask)
32
- """
33
-
34
- draw.polygon((*p0, *p1, *p2, *p3), fill=(200,0,0,100))
35
  return img
36
 
37
  def inference(img, lang):
@@ -46,12 +38,13 @@ def inference(img, lang):
46
  reader = easyocr.Reader(lang)
47
  bounds = reader.readtext(img.name)
48
  im = PIL.Image.open(img.name)
49
- im2 = PIL.Image.open(img.name)
50
- draw_boxes(im, bounds)
51
- #remove_text(im, bounds)
52
  lang = ""
53
  im.save('result.png')
54
- return ['result.png', pd.DataFrame(bounds). iloc[: , 1:2]]
 
55
 
56
  title = 'EasyOCR'
57
  description = 'Gradio demo for EasyOCR. EasyOCR demo supports 80+ languages.To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
@@ -67,7 +60,7 @@ choices = [
67
  gr.Interface(
68
  inference,
69
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
70
- [gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
71
  title=title,
72
  description=description,
73
  article=article,
 
19
  draw = ImageDraw.Draw(img, "RGBA")
20
  for bound in bounds:
21
  p0, p1, p2, p3 = bound[0]
22
+ draw.polygon((*p0, *p1, *p2, *p3), fill=(200,0,0,100))
23
+ return img
24
+
25
+ def remove_text(img,imgwmask):
26
+ masked = cv2.bitwise_and(img, img, mask=imgwmask)
 
 
 
 
 
 
 
 
27
  return img
28
 
29
  def inference(img, lang):
 
38
  reader = easyocr.Reader(lang)
39
  bounds = reader.readtext(img.name)
40
  im = PIL.Image.open(img.name)
41
+
42
+ mask = draw_boxes(im, bounds)
43
+ #remove_text(im, mask, bounds)
44
  lang = ""
45
  im.save('result.png')
46
+ mask.save('mask.png')
47
+ return ['result.png','mask.png', pd.DataFrame(bounds). iloc[: , 1:2]]
48
 
49
  title = 'EasyOCR'
50
  description = 'Gradio demo for EasyOCR. EasyOCR demo supports 80+ languages.To use it, simply upload your image and choose a language from the dropdown menu, or click one of the examples to load them. Read more at the links below.'
 
60
  gr.Interface(
61
  inference,
62
  [gr.inputs.Image(type='file', label='Input'),gr.inputs.Dropdown(choices, type="value", default="korean", label='language')],
63
+ [gr.outputs.Image(type='file', label='Output'), gr.outputs.Image(type='file', label='Output'), gr.outputs.Dataframe()],
64
  title=title,
65
  description=description,
66
  article=article,