【问题标题】:smoothen edges of pixelated binary image python code平滑像素化二进制图像python代码的边缘
【发布时间】:2019-11-12 06:15:15
【问题描述】:

我正在使用 pytesseract 将图像转换为文本,但是由于图像在调整大小时像素化,因此准确度不是 100%。应用高斯模糊会平滑边缘,但会使图像模糊,使得 OCR 无法检测到文本。 什么样的滤镜可以平滑边缘而不会使图像过于模糊。图像看起来像这样

图片

【问题讨论】:

  • 扩张和侵蚀?
  • @xiawi 这是我膨胀腐蚀后得到的图像
  • 为什么需要调整图片大小? Tesseract 应该在未更改的图像上效果最好,调整它的大小不会改善结果。

标签: python opencv image-processing ocr


【解决方案1】:

您可以对图像进行中值模糊,然后尝试一系列morphological transformations,特别是带有3x3 内核的cv2.MORPH_CLOSE 似乎在这里运行良好。您可以使用内核大小和迭代次数来获得所需的结果

import cv2

image = cv2.imread('1.png')

blur = cv2.medianBlur(image, 7)
gray = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray,125, 255,cv2.THRESH_BINARY_INV)[1]

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
close = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE, kernel, iterations=2)
result = 255 - close

cv2.imshow('thresh', thresh)
cv2.imshow('close', close)
cv2.imshow('result', result)
cv2.imwrite('result.png', result)
cv2.waitKey()

【讨论】:

    猜你喜欢
    • 2016-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-14
    • 2020-07-23
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多