首页 > 解决方案 > Python 梵文图像提取

问题描述

我试图从使用 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

标签: pythonpython-3.xdevanagari

解决方案


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

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


推荐阅读