Alimustoofaa commited on
Commit
d125def
1 Parent(s): 8758a51

Create ocr.py

Browse files
Files changed (1) hide show
  1. ocr.py +38 -0
ocr.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from paddleocr import PaddleOCR
2
+
3
+ class OCR:
4
+ def __init__(self):
5
+ self.model_det = 'models/det'
6
+ self.model_rec = 'models/rec'
7
+ self.char_dict = 'models/char_dict.txt'
8
+ self.ocr = self.paddleocr()
9
+
10
+ def paddleocr(self):
11
+ return PaddleOCR(
12
+ det_model_dir = self.model_det,
13
+ det_db_box_thresh = 0.6,
14
+ rec_model_dir = self.model_rec,
15
+ rec_image_shape = '3, 32, 100',
16
+ rec_char_dict_path = self.char_dict,
17
+ use_angle_cls = True,
18
+ show_log = False
19
+ )
20
+
21
+ def ocr_image(self, image):
22
+ return self.ocr.ocr(image)
23
+
24
+ @staticmethod
25
+ def extract_output(result):
26
+ '''
27
+ Extract the output of paddleocr.
28
+ Args:
29
+ result(list): The output of paddleocr.
30
+ Returns:
31
+ boxes(list): The list of boxes.
32
+ txts(list): The list of texts.
33
+ scores(list): The list of scores.
34
+ '''
35
+ boxes = [line[0] for line in result]
36
+ txts = [line[1][0] for line in result]
37
+ scores = [line[1][1] for line in result]
38
+ return boxes, txts, scores