hantech commited on
Commit
9488f66
·
verified ·
1 Parent(s): bd8adac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -2,6 +2,8 @@ import os
2
  import gradio as gr
3
  import omegaconf
4
  import torch
 
 
5
  import easyocr
6
  from PIL import Image
7
 
@@ -32,8 +34,9 @@ def viet_ocr_predict(inp):
32
  return out
33
  def predict(filepath):
34
  bounds = reader.readtext(filepath)
35
- inp = Image.open(filepath).convert('RGB')
36
- width, height = inp.size
 
37
  texts=''
38
  for (bbox, text, prob) in bounds:
39
  (tl, tr, br, bl) = bbox
@@ -51,9 +54,6 @@ def predict(filepath):
51
  max_y = max(tl[1], tr[1], br[1], bl[1])
52
  max_y = min(height-1, max_y)
53
  # crop the region of interest (ROI)
54
-
55
-
56
-
57
  cropped_image = inp[min_y:max_y,min_x:max_x] # crop the image
58
  cropped_image = Image.fromarray(cropped_image)
59
  out = viet_ocr_predict(cropped_image)
 
2
  import gradio as gr
3
  import omegaconf
4
  import torch
5
+ import cv2
6
+
7
  import easyocr
8
  from PIL import Image
9
 
 
34
  return out
35
  def predict(filepath):
36
  bounds = reader.readtext(filepath)
37
+ inp = cv2.imread(filepath)
38
+
39
+ width, height, _ = inp.shape
40
  texts=''
41
  for (bbox, text, prob) in bounds:
42
  (tl, tr, br, bl) = bbox
 
54
  max_y = max(tl[1], tr[1], br[1], bl[1])
55
  max_y = min(height-1, max_y)
56
  # crop the region of interest (ROI)
 
 
 
57
  cropped_image = inp[min_y:max_y,min_x:max_x] # crop the image
58
  cropped_image = Image.fromarray(cropped_image)
59
  out = viet_ocr_predict(cropped_image)