[Python] 纯文本查看 复制代码import paddlehub as hub
import cv2,copy,os
import time
class Ocr():
def __init__(self,mobile):
if mobile=='否':
# 加载移动端预训练模型
self.ocr = hub.Module(name="chinese_ocr_db_crnn_mobile")
else:
# 服务端可以加载大模型,效果更好
self.ocr = hub.Module(name="chinese_ocr_db_crnn_server")
def get_text(self,image,visualization,gpu):
if gpu ==True:
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
text=''
results = self.ocr.recognize_text(
images=[image], # 图片数据,ndarray.shape 为 [H, W, C],BGR格式;
use_gpu=gpu, # 是否使用 GPU;若使用GPU,请先设置CUDA_VISIBLE_DEVICES环境变量
output_dir='ocr_result', # 图片的保存路径,默认设为 ocr_result;
visualization=visualization, #