【问题标题】:Python devanagari image extractionPython 梵文图像提取
【发布时间】:2021-04-28 04:31:10
【问题描述】:

我尝试从使用python的手写梵文脚本图像中提取字符,但它只输出一个字母而不是整个段落。

`from keras.preprocessing.image import img_to_array
from keras.models import load_model
import numpy as np
import argparse
import imutils
import cv2

labels = [u'\u091E',u'\u091F',u'\u0920',u'\u0921',u'\u0922',u'\u0923',u'\u0924',u'\u0925',u'\u0926',u'\u0927',u'\u0915',u'\u0928',u'\u092A',u'\u092B',u'\u092c',u'\u092d',u'\u092e',u'\u092f',u'\u0930',u'\u0932',u'\u0935',u'\u0916',u'\u0936',u'\u0937',u'\u0938',u'\u0939','ksha','tra','gya',u'\u0917',u'\u0918',u'\u0919',u'\u091a',u'\u091b',u'\u091c',u'\u091d',u'\u0966',u'\u0967',u'\u0968',u'\u0969',u'\u096a',u'\u096b',u'\u096c',u'\u096d',u'\u096e',u'\u096f']
#
import numpy as np
from keras.preprocessing import image
test_image = cv2.imread("out.jpg")
image = cv2.resize(test_image, (32,32))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
image = np.expand_dims(image, axis=0)
image = np.expand_dims(image, axis=3)
print("[INFO] loading network...")
import tensorflow as tf
model = tf.keras.models.load_model("HindiModel2.h5")
lists = model.predict(image)[0]
print("The letter is ",labels[np.argmax(lists)])`

这是我使用的代码,还添加了 HindiModel2.h5 和 out.jpg 文件。

链接 - https://drive.google.com/drive/folders/12jbrYg9Dj4QAPjj_887Q-jsQmgUM7AYz?usp=sharing

主 github 链接 - https://github.com/darklord0303/Hindi-OCR

【问题讨论】:

  • 你正在做model.predict(image)[0],它只需要第 0 个答案,你可以尝试删除 [0] 然后循环遍历列表吗?
  • 也试过了,它仍然只打印一个字符,甚至不打印一个句子。
  • @SajanGohil 当我尝试您所说的方法时,我收到以下错误ValueError: Input 0 of layer sequential is incompatible with the layer: : expected min_ndim=4, found ndim=3. Full shape received: (32, 32, 1) 并且我更改了以下代码。 for img in image: lists = model.predict(img)。我不知道我做错了什么。请帮助兄弟
  • 您仍然只有一张图像,因此循环遍历图像毫无意义。我想让你尝试的是:lists = model.predict(image) 然后print([labels[np.argmax(list)] for list in lists])
  • @SajanGohil 还是一样的兄弟,只打印一个字符。 [INFO] loading network... ['२'] 当我运行 print(len(lists)) 时,它也会打印 1

标签: python python-3.x devanagari


【解决方案1】:

根据test2.pngGithub 上的测试图像,您展示的模型一次只能识别一个字符。

您可以继续使用类似 one 的新模型,也可以手动将图像划分为字符,或者制作/找到可以为您将图像划分为字符的新模型。

【讨论】:

  • 你提到的一种模型是梵文的,对吧?但我需要梵文脚本。谢谢
  • 梵文使用梵文脚本,此外这是该项目的下一次迭代-github.com/avadesh02/OCR-Devanagari。如果答案解决了您的问题,请选择它作为答案。
  • 确定兄弟,会检查它,如果有帮助,请务必将其标记为答案
  • 我得到以下错误兄弟,试图修复,但没有任何帮助。 error: (-215:Assertion failed) !_img.empty() in function 'cv::imwrite' 在第 114 行的 pagesegmenter.py 文件中出现此错误,兄弟。你能帮帮我吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-05
  • 1970-01-01
  • 2014-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-28
相关资源
最近更新 更多