-
以下是我的代码 from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
import pyautogui
import numpy
res = None
def ppocr(debug=False, use_gpu=True, drop_score=0.5, region=(0, 0, 1920, 1080), lang='ch', ocr_version='PP-OCRv4'):
"""
使用PaddleOCR进行截图OCR
:param use_gpu: 是否调用GPU
:param debug: 是否显示结果
:param drop_score: 置信度阈值
:param region: 截图范围
:param lang: 识别语言
:param ocr_version: 模型版本
:return: 识别结果 列表list
"""
global res
# 预设范围
if region == 'rule': # 队伍角色
region = (1660, 280, 200, 350)
elif region == 'ConvertData': # 转化数据
region = (1770, 290, 125, 50)
# 使用pyautogui进行截图
screenshot = pyautogui.screenshot(region=region)
# 将截图转换为numpy数组
screenshot_np = numpy.array(screenshot)
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang=lang, use_gpu=use_gpu, drop_score=drop_score, ocr_version=ocr_version)
import time
start = time.time()
result = ocr.ocr(screenshot_np, cls=True)
print(time.time() - start)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
if debug:
# 显示结果
result = result[0]
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(screenshot_np, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.png')
return res
if __name__ == '__main__':
ppocr(debug=True) |
Beta Was this translation helpful? Give feedback.
Answered by
xuan06zyx
Jun 26, 2024
Replies: 1 comment 4 replies
-
D:\PycharmProjects\DifferentialUniverse\.venv\Scripts\python.exe D:\PycharmProjects\DifferentialUniverse\ocrTest.py
[2024/06/26 01:38:55] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=True, use_xpu=False, use_npu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='C:\\Users\\xuan/.paddleocr/whl\\det\\ch\\ch_PP-OCRv2_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, use_dilation=False, det_db_score_mode='fast', det_east_score_thresh=0.8, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_sast_score_thresh=0.5, det_sast_nms_thresh=0.2, det_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='C:\\Users\\xuan/.paddleocr/whl\\rec\\ch\\ch_PP-OCRv2_rec_infer', rec_image_inverse=True, rec_image_shape='3, 32, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='D:\\PycharmProjects\\DifferentialUniverse\\.venv\\lib\\site-packages\\paddleocr\\ppocr\\utils\\ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='C:\\Users\\xuan/.paddleocr/whl\\cls\\ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, ocr=True, recovery=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', ocr_version='PP-OCRv2', structure_version='PP-StructureV2')
Traceback (most recent call last):
File "D:\PycharmProjects\DifferentialUniverse\ocrTest.py", line 58, in <module>
ppocr(debug=True, region='ConvertData')
File "D:\PycharmProjects\DifferentialUniverse\ocrTest.py", line 37, in ppocr
result = ocr.ocr(screenshot_np, cls=True)
File "D:\PycharmProjects\DifferentialUniverse\.venv\lib\site-packages\paddleocr\paddleocr.py", line 668, in ocr
dt_boxes, rec_res, _ = self.__call__(img, cls)
File "D:\PycharmProjects\DifferentialUniverse\.venv\lib\site-packages\paddleocr\tools\infer\predict_system.py", line 76, in __call__
dt_boxes, elapse = self.text_detector(img)
File "D:\PycharmProjects\DifferentialUniverse\.venv\lib\site-packages\paddleocr\tools\infer\predict_det.py", line 244, in __call__
self.input_tensor.copy_from_cpu(img)
File "D:\PycharmProjects\DifferentialUniverse\.venv\lib\site-packages\paddle\inference\wrapper.py", line 52, in tensor_copy_from_cpu
self._copy_from_cpu_bind(data)
RuntimeError: (PreconditionNotMet) The third-party dynamic library (cudnn64_8.dll) that Paddle depends on is not configured correctly. (error code is 126)
Suggestions:
1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.
2. Configure third-party dynamic library environment variables as follows:
- Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
- Windows: set PATH by `set PATH=XXX; (at ..\paddle\phi\backends\dynload\dynamic_loader.cc:312)
进程已结束,退出代码为 1 |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
3.0beta的cuda12.3可以用,我一开始没注意