ITSAIDI
commited on
Commit
·
0de3957
1
Parent(s):
8b164b3
sd
Browse files- utilitis.py +9 -11
utilitis.py
CHANGED
@@ -7,7 +7,11 @@ import numpy as np
|
|
7 |
import time
|
8 |
|
9 |
model_Hugging_path = "Noureddinesa/Output_LayoutLMv3_v7"
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
|
12 |
#############################################################################
|
13 |
#############################################################################
|
@@ -16,10 +20,6 @@ def Labels():
|
|
16 |
id2label = {v: k for v, k in enumerate(labels)}
|
17 |
label2id = {k: v for v, k in enumerate(labels)}
|
18 |
return id2label, label2id
|
19 |
-
|
20 |
-
#############################################################################
|
21 |
-
#############################################################################
|
22 |
-
ocr = PaddleOCR(use_angle_cls=False,lang='fr',rec=False)
|
23 |
|
24 |
|
25 |
def processbbox(BBOX, width, height):
|
@@ -39,10 +39,9 @@ def processbbox(BBOX, width, height):
|
|
39 |
|
40 |
|
41 |
def Preprocess(image):
|
42 |
-
ocr = PaddleOCR(use_angle_cls=False,lang='fr',rec=False)
|
43 |
image_array = np.array(image)
|
44 |
width, height = image.size
|
45 |
-
results = ocr.ocr(image_array,
|
46 |
results = results[0]
|
47 |
test_dict = {'image': image ,'tokens':[], "bboxes":[]}
|
48 |
for item in results :
|
@@ -77,12 +76,11 @@ def unnormalize_box(bbox, width, height):
|
|
77 |
def get_word(bboxes,image):
|
78 |
x_min, y_min, x_max, y_max = bboxes
|
79 |
roi = image.crop((x_min, y_min, x_max, y_max)) # Region of intrest
|
80 |
-
#roi = enhance_image(roi,1,1.5)
|
81 |
roi_np = np.array(roi) # To array
|
82 |
-
result = ocr.ocr(roi_np, cls=
|
83 |
if result != [None]:
|
84 |
-
return result[0][0][
|
85 |
-
else:
|
86 |
return ""
|
87 |
#############################################################################
|
88 |
#############################################################################
|
|
|
7 |
import time
|
8 |
|
9 |
model_Hugging_path = "Noureddinesa/Output_LayoutLMv3_v7"
|
10 |
+
ocr = PaddleOCR(use_angle_cls=False,
|
11 |
+
lang='fr',
|
12 |
+
rec=False,
|
13 |
+
use_tensorrt = True
|
14 |
+
)
|
15 |
|
16 |
#############################################################################
|
17 |
#############################################################################
|
|
|
20 |
id2label = {v: k for v, k in enumerate(labels)}
|
21 |
label2id = {k: v for v, k in enumerate(labels)}
|
22 |
return id2label, label2id
|
|
|
|
|
|
|
|
|
23 |
|
24 |
|
25 |
def processbbox(BBOX, width, height):
|
|
|
39 |
|
40 |
|
41 |
def Preprocess(image):
|
|
|
42 |
image_array = np.array(image)
|
43 |
width, height = image.size
|
44 |
+
results = ocr.ocr(image_array, cls=False,rec = True)
|
45 |
results = results[0]
|
46 |
test_dict = {'image': image ,'tokens':[], "bboxes":[]}
|
47 |
for item in results :
|
|
|
76 |
def get_word(bboxes,image):
|
77 |
x_min, y_min, x_max, y_max = bboxes
|
78 |
roi = image.crop((x_min, y_min, x_max, y_max)) # Region of intrest
|
|
|
79 |
roi_np = np.array(roi) # To array
|
80 |
+
result = ocr.ocr(roi_np, cls=False,det = False,rec = True)
|
81 |
if result != [None]:
|
82 |
+
return result[0][0][0]
|
83 |
+
else :
|
84 |
return ""
|
85 |
#############################################################################
|
86 |
#############################################################################
|