mirror of
https://github.com/sml2h3/ocr_api_server.git
synced 2025-05-02 20:49:23 +08:00
25 lines
933 B
Python
25 lines
933 B
Python
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()
|