moxiaoying commited on
Commit
d9c8d73
·
verified ·
1 Parent(s): bf03a84

Create services.py

Browse files
Files changed (1) hide show
  1. app/services.py +24 -0
app/services.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import ddddocr
2
+ from typing import Union, List, Optional
3
+
4
+ class OCRService:
5
+ def __init__(self):
6
+ self.ocr = ddddocr.DdddOcr()
7
+ self.det = ddddocr.DdddOcr(det=True)
8
+ self.slide = ddddocr.DdddOcr(det=False, ocr=False)
9
+
10
+ def ocr_classification(self, image: bytes, probability: bool = False, charsets: Optional[str] = None, png_fix: bool = False) -> Union[str, dict]:
11
+ if charsets:
12
+ self.ocr.set_ranges(charsets)
13
+ result = self.ocr.classification(image, probability=probability, png_fix=png_fix)
14
+ return result
15
+
16
+ def slide_match(self, target: bytes, background: bytes, simple_target: bool = False) -> List[int]:
17
+ result = self.slide.slide_match(target, background, simple_target=simple_target)
18
+ return result
19
+
20
+ def detection(self, image: bytes) -> List[List[int]]:
21
+ bboxes = self.det.detection(image)
22
+ return bboxes
23
+
24
+ ocr_service = OCRService()