Spaces:
Paused
Paused
File size: 932 Bytes
d9c8d73 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import ddddocr
from typing import Union, List, Optional
class OCRService:
def __init__(self):
self.ocr = ddddocr.DdddOcr()
self.det = ddddocr.DdddOcr(det=True)
self.slide = ddddocr.DdddOcr(det=False, ocr=False)
def ocr_classification(self, image: bytes, probability: bool = False, charsets: Optional[str] = None, png_fix: bool = False) -> Union[str, dict]:
if charsets:
self.ocr.set_ranges(charsets)
result = self.ocr.classification(image, probability=probability, png_fix=png_fix)
return result
def slide_match(self, target: bytes, background: bytes, simple_target: bool = False) -> List[int]:
result = self.slide.slide_match(target, background, simple_target=simple_target)
return result
def detection(self, image: bytes) -> List[List[int]]:
bboxes = self.det.detection(image)
return bboxes
ocr_service = OCRService() |