使用Python进行字符分割

我正在使用Python的计算机视觉技术检测手写符号。我已经在一个包含单个字符的数据集上训练了一个卷积神经网络(CNN),但现在我想从图像中提取字符,以便对单个字符进行预测。最佳的实现方法是什么?我将要处理的 handwritten 文本不是连笔书写,并且字符之间会有明显的间隔。


回答:

你可以使用查找轮廓并用框包围它们的方法。

image = cv2.imread("filename") image = cv2.fastNlMeansDenoisingColored(image,None,10,10,7,21)gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)res,thresh = cv2.threshold(gray,150,255,cv2.THRESH_BINARY_INV) #threshold kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))  dilated = cv2.dilate(thresh,kernel,iterations = 5)  val,contours, hierarchy =             cv2.findContours(dilated,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)  coord = [] for contour in contours:        [x,y,w,h] = cv2.boundingRect(contour)         if h>300 and w>300:             continue         if h<40 or w<40:             continue        coord.append((x,y,w,h))  coord.sort(key=lambda tup:tup[0]) # if the image has only one sentence sort in one axis count = 0 for cor in coord:        [x,y,w,h] = cor        t = image[y:y+h,x:x+w,:]        cv2.imwrite(str(count)+".png",t)  print("number of char in image:", count)

Related Posts

在使用k近邻算法时,有没有办法获取被使用的“邻居”?

我想找到一种方法来确定在我的knn算法中实际使用了哪些…

Theano在Google Colab上无法启用GPU支持

我在尝试使用Theano库训练一个模型。由于我的电脑内…

准确性评分似乎有误

这里是代码: from sklearn.metrics…

Keras Functional API: “错误检查输入时:期望input_1具有4个维度,但得到形状为(X, Y)的数组”

我在尝试使用Keras的fit_generator来训…

如何使用sklearn.datasets.make_classification在指定范围内生成合成数据?

我想为分类问题创建合成数据。我使用了sklearn.d…

如何处理预测时不在训练集中的标签

已关闭。 此问题与编程或软件开发无关。目前不接受回答。…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注