OCR EasyOCR + PaddleHub 光学字符识别(Optical Character Recognition, OCR)
EasyOCR
pip install opencv-python
pip3 install easyocr
简单测试一下
import os
import easyocr
import cv2
from matplotlib import pyplot as plt
import numpy as np
import ssl
ssl._create_default_https_context = ssl._create_unverified_contextIMAGE_PATH = 'Perform-OCR-using-C.jpg'
IMAGE_PATH = 'a.PNG'reader = easyocr.Reader(['en'],gpu=False)
result = reader.readtext(IMAGE_PATH,paragraph="False")
print(result)
问题处理
模型下载
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
# 全局取消证书验证
[easyocr下载模型失败](https://www.cnblogs.com/yqpy/p/14344355.html)
有时不显示下载进度,手动“enter”助力显示:
opencv报错
cv2.error: Unknown C++ exception from OpenCV code
pip install opencv-python==4.1.2.30 -i https://pypi.tuna.tsinghua.edu.cn/simple
代码测试
import os
import easyocr
import cv2
from matplotlib import pyplot as plt
import numpy as np
import ssl
ssl._create_default_https_context = ssl._create_unverified_contextIMAGE_PATH = 'Perform-OCR-using-C.jpg'# https://blog.aspose.com/wp-content/uploads/sites/2/2020/05/Perform-OCR-using-C.jpgreader = easyocr.Reader(['ch_sim'],gpu=False)
result = reader.readtext(IMAGE_PATH,paragraph="False")
print(result)img = cv2.imread(IMAGE_PATH)
top_left = tuple(result[0][0][0])
bottom_right = tuple(result[0][0][2])
text = result[0][1]
font = cv2.FONT_HERSHEY_SIMPLEX
img = cv2.rectangle(img,top_left,bottom_right,(0,255,255),3)
img = cv2.putText(img,text,bottom_right, font, 0.5,(0,255,0),2,cv2.LINE_AA)
plt.figure(figsize=(10,10))
plt.imshow(img)
plt.show()
字体处理
https://ultralytics.com/assets/Arial.ttf
Python图像处理库PIL的ImageFont模块介绍
在如下地址拷贝字体文件到项目:
C:\Windows\Fonts
[官方文档](https://www.easyproject.cn/easyocr/zh-cn/index.jsp#readme)
[代码教程:使用 EasyOCR 从图像中检测文本](https://zhuanlan.zhihu.com/p/413310223)
[添加链接描述](https://pythondict.com/ai/easyocr/)
[视频教程](https://www.bilibili.com/video/BV1x3411Y72t?)
报错
File "C:\Users\user\Anaconda3\lib\site-packages\easyocr\detection.py", line 2, in <module>import torch.backends.cudnn as cudnn ModuleNotFoundError: No module named 'torch.backends'
PaddleHub一键OCR
安装环境
# python环境
conda create --name paddle_env python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ # 安装paddlepaddle 默认安装CPU版本 https://www.paddlepaddle.org.cn/ 不使用vpn
pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple# 安装hub https://github.com/PaddlePaddle/PaddleHub/blob/release/v2.1/README_ch.md
pip install paddlehub -i https://mirror.baidu.com/pypi/simple# 安装模型
hub install chinese_ocr_db_crnn_server==1.1.0
使用
def recognize_text(images=[],paths=[],use_gpu=False,output_dir='ocr_result',visualization=False,box_thresh=0.5,text_thresh=0.5)参数paths (list[str]): 图片的路径;
images (list[numpy.ndarray]): 图片数据,ndarray.shape 为 [H, W, C],BGR格式;
use_gpu (bool): 是否使用 GPU;若使用GPU,请先设置CUDA_VISIBLE_DEVICES环境变量
box_thresh (float): 检测文本框置信度的阈值;
text_thresh (float): 识别中文文本置信度的阈值;
visualization (bool): 是否将识别结果保存为图片文件;
output_dir (str): 图片的保存路径,默认设为 ocr_result;
返回res (list[dict]): 识别结果的列表,列表中每一个元素为 dict,各字段为:
data (list[dict]): 识别文本结果,列表中每一个元素为 dict,各字段为:
text(str): 识别得到的文本
confidence(float): 识别文本结果置信度
text_box_position(list): 文本框在原图中的像素坐标,4*2的矩阵,依次表示文本框左上,右上,右下,左下顶点的坐标 如果无识别结果则data为[]
save_path (str, optional): 识别结果的保存路径,如不保存图片则save_path为''
import paddlehub as hub
import cv2ocr = hub.Module(name="chinese_ocr_db_crnn_server")
result = ocr.recognize_text(images=[cv2.imread(IMAGE_PATH)])
print(123)
ImportError: This module requires the shapely, pyclipper tools. The running environment does not meet the requirements. Please install the two packages.
pip install shapely
pip install pyclipper
对于图片
https://blog.aspose.com/wp-content/uploads/sites/2/2020/05/Perform-OCR-using-C.jpg
运行1000的时间为212秒
官方教程链接,官方中还有创建网络服务功能。
paddle运行的报错:
The _initialize method in HubModule will soon be deprecated, you can use the __init__() to handle the initialization of the object
W0423 10:10:09.251121 620 analysis_predictor.cc:1350] Deprecated. Please use CreatePredictor instead.
返回值
[{'save_path': '',
'data': [{'text': '****年**月**日星期* **:**:**', 'confidence': 0.9879583120346069, 'text_box_position': [[58, 33], [1024, 33], [1024, 96], [58, 96]]}, {'text': '*****', 'confidence': 0.9997267723083496, 'text_box_position': [[960, 201], [1480, 189], [1485, 522], [965, 534]]}, {'text': '*****', 'confidence': 0.9997847676277161, 'text_box_position': [[1066, 1230], [1176, 1230], [1176, 1374], [1066, 1374]]}]
}]
'text_box_position': [[58, 33], [1024, 33], [1024, 96], [58, 96]]作为一个方形区域的四角,分别为 左上,右上,右下,左下的顺时针顺序。data = result[0]['data']
OCR EasyOCR + PaddleHub 光学字符识别(Optical Character Recognition, OCR)相关推荐
- 光学字符识别 OCR (Optical Character Recognition)是什么?
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形状翻译 ...
- 光学字符识别(OCR,Optical Character Recognition)
简介 OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,通过检测暗.亮的模式确定其形状,然后用字符识别方法将形 ...
- OCR(Optical Character Recognition,光学字符识别)技术详解
OCR(Optical Character Recognition,光学字符识别)技术是一种将图像中的文字信息转换为文本的技术.在计算机视觉和人工智能领域,OCR 技术是一个非常重要的应用,它可以帮助 ...
- Python,OpenCV中的光学字符识别(OCR Optical Character Recognition)
Python,OpenCV中的光学字符识别(OCR Optical Character Recognition 1. 什么是OCR? 2. 光学字符识别简史 3. 光学字符识别的应用 4. OSD 方 ...
- 关于OCR(Optical Character Recognition,光学字符识别)
OCR(Optical Character Recognition,光学字符识别),是属于图型识别(Pattern Recognition,PR)的一门学问.其目的就是要让计算机知道它到底看到了什么, ...
- OCR(Optical Character Recognition 光学字符识别)扫盲
了解OCR OCR是英文Optical Character Recognition 的缩写,中文意思就是通过光学技术对文字进行识别.OCR概念的产生是在1929年,德国的科学家Tausheck首先提出 ...
- A Survey on Optical Character Recognition System 光学字符识别系统综述
论文题目: 2017-A Survey on Optical Character Recognition System 摘要 光学字符识别(OCR)是近年来研究的热点.它被定义为将文档图像数字化为 ...
- OCR技术(光学字符识别)
什么是OCR? OCR英文全称是optical character recognition,中文叫光学字符识别.它是利用光学技术和计算机技术把印在或者写在纸上的 文字读取出来,并转换成一种计算机能够接 ...
- 入门深度学习OCR(Optical character recognition)开发
前言: 光学字符识别(OCR)指对文本资料的图像文件进行分析识别处理,获取文字及版面信息的过程.目前OCR主要落地应用场景包括:自然场景文本检测识别.文档类印刷体文本检测识别.手写体文本检测识别.自然 ...
最新文章
- JakartaEE Exception: Invalid bound statement (not found): com.mazaiting.blog.dao.UserDao.selectUs...
- 减少亚稳态导致错误,提高系统的MTBF
- php 怎么防止提交空记录,为什么空提交什么都不提示?
- python的用算法进制转换详解_学习python第五天进制转换
- 1、管理员登录中间件和注销
- 恭喜你,20级考研生!你将在考研前看到这篇最靠谱的学习方法!
- Linux 重启php
- python的requests模块功能_python-Requests模块的使用
- 20145326蔡馨熤《网络对抗》——信息搜集与漏洞扫描
- C#之Enum中的Flag
- SOFABolt 源码分析
- codeM美团编程大赛初赛B轮E题
- 求一天的起始和结束(时间戳)和一个月的第一天和最后一天
- 联发科mt8516价格_揭秘联发科MT8516单颗芯片破千万背后的故事
- 数据库三范式设计习题
- CentOS离线安装Tomcat
- 利用python目录化整理PPT素材文件
- kernel停在Starting kernel 分析
- 最新网站生成APP源代码+Flutter项目/带控制端
- Unity 得到游戏组件的常用的两种方法