【问题标题】:Unable to properly read text from image which has a Color text in python无法从 python 中具有彩色文本的图像中正确读取文本
【发布时间】:2019-12-09 07:06:00
【问题描述】:

到目前为止我尝试了什么。大部分图像都是黑色的,背景是白色的。

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)

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

输出:

高级油

由 POR 警报器制成的水壶渲染 9s!

fatworks €)

净重。 4月2日(3966)

如何解决这个问题。

【问题讨论】:

  • 在应用image_to_string之前尝试图像阈值化或饱和度二值化。
  • @Lukashou-AGH 你能帮我解决这个问题吗?请。

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


【解决方案1】:

我的意思是

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

【讨论】:

    猜你喜欢
    • 2021-03-31
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多