python-3.x - 无法正确读取 python 中具有颜色文本的图像中的文本

标签 python-3.x opencv machine-learning computer-vision python-tesseract

到目前为止我尝试过的。大多数图像都工作正常,文本为黑色,背景为白色。

from PIL import Image
import pytesseract
import nltk
import cv2

imageName = "p9.png"
img = cv2.imread(imageName,cv2.IMREAD_COLOR) #Open the image from which charectors has to be recognized
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey to reduce detials
gray = cv2.bilateralFilter(gray, 11, 17, 17) #Blur to reduce noise
original = pytesseract.image_to_string(gray, config='')
print (original)

但下图我没有给出正确的文字。

enter image description here

输出:

REMIUM OKING OIL

KETTLE-RENDERED 9s MADE FROM POR siren!

fatworks €)

NET WT. 4 02 (3966)

如何解决此问题。

最佳答案

我的意思是

imageName = "p9.png"
img = cv2.imread(imageName,cv2.IMREAD_COLOR) #Open the image from which charectors has to be recognized
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #convert to grey to reduce detials
gray = cv2.bilateralFilter(gray, 11, 17, 17) #Blur to reduce noise
img = cv2.adaptiveThreshold(gray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,71,2)
#img = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,\
            cv2.THRESH_BINARY,11,2)
original = pytesseract.image_to_string(img, config='')

尝试使用此函数的参数来找到最适合您的 cv2.adaptiveThreshold(src,maxValue,adaptiveMethod,thresholdType,blockSize,C[,dst])

我还在这里保留了原始教程的链接:https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_thresholding/py_thresholding.html

关于python-3.x - 无法正确读取 python 中具有颜色文本的图像中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59244032/

相关文章:

python - 即使函数适用于每个列系列,DataFrame.apply 与 str.extract 也会引发错误

c# - 通过 emgu 或 opencv 基于图像中的某些颜色进行对象检测的最快方法

iOS 和 OpenCV : Image Registration/Alignment

python - 如何继续处理车牌裁剪?

python - Keras 如何计算多类分类问题的验证准确率和训练准确率?

machine-learning - kNN 中用于分类的理想 k 值

python - Model.clean() 与 Model.clean_fields()

mysql - 无法从 django 连接到 mysql 数据库

Python 重载不存在的运算符有效,为什么?

machine-learning - h2o 如何返回 mcc 值