尝试对字符进行分段并将其保存以便对文件进行映像.但是轮廓是以不同的顺序绘制的吗? [英] Trying to segment characters and save it in order to image files. But contours are being drawn in a different order?

查看:104
本文介绍了尝试对字符进行分段并将其保存以便对文件进行映像.但是轮廓是以不同的顺序绘制的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是图像输入.

使用python opencv.我进行了一些预处理,并使用

Using python opencv. I did some pre-processing and found contours using

contours,hierarchy = cv2.findContours(thresh,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)

然后我执行以下操作来保存每个字符

then i did the following to save each character

img1 = cv2.imread("test26.png")
nu = 1
fin = "final"
for cnt in contours:
    x,y,w,h = cv2.boundingRect(cnt)
    img2 = img1[y:y+h, x:x+w]
    img3 = Image.fromarray(img2)
    filename = fin + str(nu) + ".png"
    nu = nu + 1
    img3.save(filename)

但是字符以树状顺序保存.我不了解订单.

But characters are saved in a tree like order. I don't understand the order.

我的目的是逐个字符地获取字符并按顺序保存并另存为文本.

my intention is to get character by character and ocr it in order and save as text.

推荐答案

您可以尝试使用轮廓中心找到字母的位置.

You can try to find the location of letter by using the center of contours.

M = cv2.moments(contours)
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])

然后您可以使用cX和cY查找字符的顺序(如果仅一行,则仅使用cX)

Then you can find the order of characters with using cX and cY (If only one line, you use only cX)

这篇关于尝试对字符进行分段并将其保存以便对文件进行映像.但是轮廓是以不同的顺序绘制的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆