首页 > 解决方案 > 从图像上字符的坐标(横坐标和纵坐标)重建文本

问题描述

我正在尝试从图像中重建 Texte在此处输入图像描述

我已经得到了被包围元素的坐标,这里是代码:

NL = list()
for element in range(0, len(ajustX), 1):
    t= (dataList[element], ajustX[element], ajustY[element])
    NL.append(t)
NL = sorted(NL, key=lambda element: (element[2], element[1]))

print(type(ajustX), type(ajustY),type(NL),type(dataList))
print("\n"+"ajustX" +str(dataList)+"\n"+"X coordinates  "+str(ajustX)+"\n"+"Y coordinates  "+str(ajustY)+"\n"+"\n"+"NL:"+str(NL))

这是我按 X 降序对坐标进行排序的输出:

<class 'list'> <class 'list'> <class 'list'> <class 'list'>

letter list['T', 'O', 'T', 'A', 'L', '1', '2', '.', '1', 'O']
X coordinates  [28, 116, 205, 295, 384, 917, 1004, 1120, 1184, 1272]
Y coordinates  [33, 33, 33, 33, 34, 38, 38, 89, 38, 38]

NL:[('T', 28, 33), ('O', 116, 33), ('T', 205, 33), ('A', 295, 33), ('L', 384, 34), ('1', 917, 38), ('2', 1004, 38), ('1', 1184, 38), ('O', 1272, 38), ('.', 1120, 89)]

我正在寻找一种通过保存在文件中来使用坐标(NL)动态重建图像(即使我有具有不同坐标的图像)的方法。

代码:

for element in range(0, len(NL), 1): 
    fichier = open("data.txt", "a")
    #Do something and write

在保存文件时,我想要:

TOTAL 12.10

感谢您的帮助和建议

标签: pythonpython-3.xalgorithmjupyter-notebook

解决方案


推荐阅读