PaddleOCR在window配置过程

  1. python 3.7 cuda10.2 cudnn 7.6
  2. 创建虚拟环境 ocr python3.7
  3. 安装paddlepaddle conda install paddlepaddle-gpu==2.4.2 cudatoolkit=10.2 --channel [https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/](https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/)
  4. 先安装 PyWavelets
  5. 安装paddleocr pip install paddleocr -i https://mirror.baidu.com/pypi/simple
  6. 安装shapely
  7. pip install -i [https://pypi.tuna.tsinghua.edu.cn/simple](https://pypi.tuna.tsinghua.edu.cn/simple) --trusted-host pypi.tuna.tsinghua.edu.cn --user pyzmq==19.0.2
import paddle
import paddleocr
import os
from paddleocr import PaddleOCR
import numpy as np
import cv2
import matplotlib.pyplot as plt
import os
from PIL import Image
import glob
import random
import re
import json
print(paddle.__version__)
#2.4.1
print(paddleocr.__version__)
#2.6.1.3
# os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
SUPPORT_DET_MODEL = ['DB']
VERSION = '2.6.1.0'
SUPPORT_REC_MODEL = ['CRNN', 'SVTR_LCNet']
BASE_DIR = os.path.expanduser("~/.paddleocr/")
DEFAULT_OCR_MODEL_VERSION = 'PP-OCRv3'
ocr = PaddleOCR(use_angles_cls=True, use_gpu=False)
def draw_img(img_path,boxes):
    save_root = 'data/resocr/'
    img_name = img_path.split('\\')[1]
    img = cv2.imread(img_path)
    for box in boxes:
        box = np.reshape(np.array(box),[-1,1,2]).astype(np.int64)
        img = cv2.polylines(np.array(img), [box], True, (255,0,0),2)
        plt.figure(figsize=(10,10))
        save_file = save_root+img_name
        plt.imshow(img)
        plt.savefig(save_file)
imgp = 'data\\test.jpg'
print(ocr.args)
res = ocr.ocr(imgp)
print(res)
boxes = []
texts = []
for j in range(len(res[0])):
    boxes.append(res[0][j][0])
    texts.append(res[0][j][1][0])
draw_img(imgp,boxes)
import cv2

from paddleocr import PaddleOCR, draw_ocr



# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch")  # need to run only once to download and load model into memory
img_path = './data/test.jpg'
result = ocr.ocr(img_path, cls=True)
for line in result:
    print(line)
# 显示结果
from PIL import Image
image = Image.open(img_path).convert('RGB')
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(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

成功输出!
1678248383281.png

遇到的问题
  • cfda6a11d95a95d9912f00bd6d9c4de.png

下载whl文件

  • 092c722b53e1aa391fa2e48dfdd070e.png

pillow版本过高 更换版本为8.3.2

  • 55232fb198fc205e2d8436972b6d5cf.png

删除对应虚拟环境下G:\Anaconda\envs\ocr\Library\bin libiomp5md.dll文件

  • if scores is not None and (scores[i] < drop_score or TypeError: ‘<’ not supported between instances of ‘tuple’ and ‘float’

更换paddleocr的版本,最新版本是2.6,V2.6版本调用的ocr.ocr返回的部署一个数组,是一个字符串,需要进行转换 pip install paddleocr==2.5.0.3 -i [https://mirror.baidu.com/pypi/simple](https://mirror.baidu.com/pypi/simple)

参考链接

测试代码都是直接copy的两位大佬的,我纯新手小白!下面附大佬原文链接
https://zhuanlan.zhihu.com/p/523972865
https://www.rstk.cn/news/32313.html?action=onClick

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值