hantech commited on
Commit
4c5b48d
β€’
1 Parent(s): 957af04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -4
app.py CHANGED
@@ -6,7 +6,7 @@ import gradio as gr
6
  import torch
7
  import easyocr
8
  import omegaconf
9
- import numpy
10
 
11
  from vietocr.vietocr.tool.predictor import Predictor
12
  from vietocr.vietocr.tool.config import Cfg
@@ -30,7 +30,7 @@ def draw_boxes(image, bounds, color='yellow', width=2):
30
  return image
31
 
32
  def inference(filepath, lang):
33
- img = Image.open(filepath).convert("RGB")
34
  reader = easyocr.Reader(lang)
35
  bounds = reader.readtext(filepath)
36
  new_bounds=[]
@@ -47,9 +47,8 @@ def inference(filepath, lang):
47
  max_y = max(tl[1], tr[1], br[1], bl[1])
48
  # crop the region of interest (ROI)
49
 
50
- cropped_image = img.crop((min_x, min_y, max_x, max_y)) # crop the image
51
  cropped_image = Image.fromarray(cropped_image)
52
- cropped_image = cropped_image.convert("RGB")
53
  out = recognitor.predict(cropped_image)
54
  print(out)
55
  new_bounds.append((bbox,text, out, prob))
 
6
  import torch
7
  import easyocr
8
  import omegaconf
9
+ import cv2
10
 
11
  from vietocr.vietocr.tool.predictor import Predictor
12
  from vietocr.vietocr.tool.config import Cfg
 
30
  return image
31
 
32
  def inference(filepath, lang):
33
+ img = cv2.imread(filepath)
34
  reader = easyocr.Reader(lang)
35
  bounds = reader.readtext(filepath)
36
  new_bounds=[]
 
47
  max_y = max(tl[1], tr[1], br[1], bl[1])
48
  # crop the region of interest (ROI)
49
 
50
+ cropped_image = img[(min_x:(max_x - min_x), min_y:(max_y - min_y)] # crop the image
51
  cropped_image = Image.fromarray(cropped_image)
 
52
  out = recognitor.predict(cropped_image)
53
  print(out)
54
  new_bounds.append((bbox,text, out, prob))