Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
import torch
|
| 7 |
import easyocr
|
| 8 |
import omegaconf
|
| 9 |
-
import
|
| 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 =
|
| 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
|
| 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))
|