python - 使用 cv2 在距离上裁剪图像
问题描述
我是深度学习和图像处理的新手,但我已经实现了以下用于拆分阿拉伯字符的代码,但我的代码无法识别字符,它只能找到整个单词。 这是代码检测到的整个单词
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
image = cv.imread('hamd.png')
height, width, depth = image.shape
print(image.shape)
image = cv.resize(image, dsize=(width*5, height*4), interpolation=cv.INTER_CUBIC)
print(image.shape)
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
ret,thresh = cv.threshold(gray,127,255,cv.THRESH_BINARY_INV)
kernel = np.ones((5,5), np.uint8)
img_dilation = cv.dilate(thresh, kernel, iterations=1)
gsblur=cv.GaussianBlur(img_dilation,(5,5),0)
ctrs, hier = cv.findContours(gsblur.copy(), cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
m = list()
sorted_ctrs = sorted(ctrs, key=lambda ctr: cv.boundingRect(ctr)[0])
pchl = list()
dp = image.copy()
for i, ctr in enumerate(sorted_ctrs):
x, y, w, h = cv.boundingRect(ctr)
cv.rectangle(dp,(x-10,y-10),( x + w + 10, y + h + 10 ),(90,0,255),9)
plt.imshow(dp)
现在我想知道如何在两个字符之间的距离上分割字符?我的意思如下图所示: 这就是我想要的
解决方案
推荐阅读
- python - 这段代码是否增加了输入数据?
- arrays - 在Objective c中组合两个NSMutableArray
- sql - 如何创建可以生成组合三个表的表的 SQL Server 存储过程
- python - 总和小于或等于给定数字的二维数组中的最大成本值
- c# - Web 应用程序将值从列表发送到 Java Script 中的函数
- javascript - 为什么我无法访问函数属性?
- android - 无法解决方法添加 YouTubePlayerSupportFragment 2020
- c# - 在 C# 中更改字段属性
- c++ - _mm256_store_epi32 未声明
- swift - 从另一个 .swift 文件调用 ViewController 函数