machine-learning - python中的字符分割
问题描述
我正在使用 python 中的计算机视觉检测手写符号。我在单个字符的数据集上训练了一个 cnn,但现在我希望能够从图像中提取字符以便对单个字符进行预测。做这个的最好方式是什么?我将使用的手写文本不会是草书,字符之间会有明显的分隔。
解决方案
在下面的代码片段中,boxes 变量具有图像中每个字符的尺寸。
import cv2
import pytesseract
file = '/content/Captchas/image22.jpg'
img = cv2.imread(file)
h, w, _ = img.shape
boxes = pytesseract.image_to_boxes(img)
for b in boxes.splitlines():
b = b.split(' ')
img = cv2.rectangle(img, (int(b[1]), h - int(b[2])), (int(b[3]), h - int(b[4])), (0, 255, 0), 2)
cv2_imshow(img)
print(boxes)
推荐阅读
- java - 运行 Eclipse 时出错:由于 java.io.EOFException 初始化存储时出错
- javascript - 如何覆盖 javascript 命名空间函数?
- android - 谷歌语音转文本:额外语言设置为“kn”但不起作用
- templates - 在显示字段列表模板中打开一个 url
- python - flask:单元测试时,request.authorization 始终为 None
- scala - 将结构列转换为 Scala 列表
- python - 如何使用 boto3 更新 dynamodb 中项目的多个属性
- mysql - 无法连接到远程 MySQL 服务器错误 2003 (HY000)
- swift - 为什么我不能使用 Swift 解开这个可选值?
- php - 如何在 php 7.2 中设置 mongodb 环境