sbt-idp/cope2n-ai-fi/api/OCRBase/text_detection.py

23 lines
592 B
Python
Raw Permalink Normal View History

2023-11-30 11:22:16 +00:00
# Copyright (c) OpenMMLab. All rights reserved.
from distutils.command.config import config
from mmdet.apis import inference_detector, init_detector
from PIL import Image
from io import BytesIO
config = "model/yolox_s_8x8_300e_cocotext_1280.py"
checkpoint = "model/best_bbox_mAP_epoch_294.pth"
device = "cpu"
def read_imagefile(file) -> Image.Image:
image = Image.open(BytesIO(file))
return image
def detection_predict(image):
model = init_detector(config, checkpoint, device=device)
# test a single image
result = inference_detector(model, image)
return result