|-转 汉字目标点选识别-ddddocr(返回识别的内容和位置)
实测有效 ,中文有时会识别认为是英文,除非加载训练好的模型数据否则识别的准确率一般
汉字目标点选识别-ddddocr_ddddocr官方文档-CSDN博客
目录
一、ddddocr介绍
- ddddocr 新的目标检测识别 1.3功能
- 安装 pip install ddddocr
- star哲哥免费开源的识别项目https://github.com/sml2h3/ddddocr
二、识别效果
三、代码
- 图片demo
- 代码 ,更多详细介绍看ddddocr 新的目标检测识别 1.3功能
"""
@author:十一姐
@desc: ddddocr目标识别
@time: 2022/01/09
"""
from io import BytesIO
import ddddocr
from PIL import Image, ImageDraw, ImageFont
import sys
import json
class Ddddocr:
def __init__(self):
self.ocr = ddddocr.DdddOcr(show_ad=False)
self.xy_ocr = ddddocr.DdddOcr(det=True, show_ad=False)
def ddddocr_identify(self, captcha_bytes):
return self.ocr.classification(captcha_bytes)
def draw_img(self, content, xy_list):
"""画出图片"""
# 填字字体
font_type = "./msyhl.ttc"
font_size = 20
font = ImageFont.truetype(font_type, font_size)
# 识别
img = Image.open(BytesIO(content))
draw = ImageDraw.Draw(img)
words = []
for row in xy_list:
# 框字
x1, y1, x2, y2 = row
draw.line(([(x1, y1), (x1, y2), (x2, y2), (x2, y1), (x1, y1)]), width=1, fill="red")
# 裁剪出单个字
corp = img.crop(row)
img_byte = BytesIO()
corp.save(img_byte, png)
# 识别出单个字
word = self.ocr.classification(img_byte.getvalue())
words.append(word)
# 填字
y = y1 - 30 if y2 > 300 else y2
draw.text((int((x1 + x2)/2), y), word, font=font, fill="red")
img.show()
return words
def ddddocr_clcik_identify(self, content, crop_size=None):
"""目标检测识别"""
img = Image.open(BytesIO(content))
# print(img.size)
if crop_size:
img = img.crop(crop_size)
img_byte = BytesIO()
img.save(img_byte, png)
content = img_byte.getvalue()
xy_list = self.xy_ocr.detection(content)
words = self.draw_img(content, xy_list)
return dict(zip(words, xy_list))
def case_demo(self, con):
"""点选识别结果"""
click_identify_result = self.ddddocr_clcik_identify(con, (0, 0, 344, 344))
img = Image.open(BytesIO(con))
img = img.crop((0, 344, 344, 384))
img_byte = BytesIO()
img.save(img_byte, png)
# identify_words = self.ocr.classification(img_byte.getvalue())
# print(click_identify_result)
# words_dict = {}
# for word in identify_words:
# words_dict[word] = click_identify_result.get(word)
# print(words_dict)
img_xy = {}
for key, xy in click_identify_result.items():
img_xy[key] = (int((xy[0] + xy[2]) / 2), int((xy[1] + xy[3]) / 2))
# print(img_xy)
j = json.dumps(img_xy)# dict字典格式 转 json 20241005
print(j)
with open(r./8320423853e84b499be0b81d40c7f259.jpg, rb) as f:
con1 = f.read()
Ddddocr().case_demo(con1)
...
浏览更多内容请先登录。
立即注册
分享的网址网站均收集自搜索引擎以及互联网,非查问网运营,查问网并没有提供其服务,请勿利用其做侵权以及违规行为。
更新于:2024-10-05 19:23:17
相关内容
python代码整理(2022年4月-2024年3月)
Python和PHP获取百度url跳转的真实地址代码(2022年4月实测有效)
Pip/python-如何查看已安装的包有哪些版本?如何查看某个包存在哪些版本?pip...
用undetected_chromedriver代替selenium解决浏览器打不开网页
sublime text下 Python 问题:TabError: inconsistent use of tabs and s...
Python的扩展和模块安装时遇到的问题整理
windows环境下python3安装Crypto扩展
pip install 报错 ERROR: Can not execute setup.py since setuptools i...
运行python -V 报错 -bash: python: command not found
protobuf requires Python ‘>=3.7‘ but the running Python is 3.6.5的解...
python 学习中遇到的问题整理
没有使用asynccontextmanager ,但是报cannot import name 'asynccontextman...
python3.10.0+pyinstaller4.7打包,IndexError: tuple index out of range...
error: Microsoft Visual C++ 14.0 or greater is required.
安装conda搭建python环境(保姆级教程)
学习飞浆过程中遇到“缺少paddle.fluid”
[NLP实践01]simpletransformers安装和文本分类简单实现
primeqa 安装requirements时报错
sublime text下 Python 问题:TabError: inconsistent use of tabs and s...
uiautomation报错 No module named 'comtypes.stream' Can not load UIA...
解决无法加载UIAutomationCore.dll的报错
汉字目标点选识别-ddddocr(返回识别的内容和位置)
python 常用命令
opencv报错及解决:AttributeError: module ‘cv2‘ has no attribute ‘...
AttributeError: module 'cv2.cv2' has no attribute 'cv'
sublime text常用快捷键及多行列模式批量操作教程
python配置opencv环境后,读取图片,报错:can‘t open/read file: check f...
各种服务器通用搭建python训练模型用的环境,以训练SoloSpeech为列子
推荐内容