python - 使用 python 从不良闪电图像中分割文本

标签 python opencv image-processing image-segmentation text-segmentation

我有三种类型的图像,想从中分割出文本。所以我得到了一个干净的二值化 img,如下面的第一张图片。三种类型的图片如下

我尝试过各种技术,但总有一些情况会失败。我首先尝试使用 otsu 算法对 img 进行阈值处理,但它在下面的图像中给出了不好的结果

我尝试了 Guassianbilateral 和普通模糊内核,但并没有过多地增强结果

任何人都可以提供帮助!

代码是我从中得到的最好的结果

import cv2

gray = cv2.imread("/home/shrouk/Pictures/f2.png", 0)
thresholded = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
cv2.imshow("img", thresholded)

这是我需要的最终结果 enter image description here

这是第一种失败的图像。它失败了,因为图像右侧的文本灰度级变浅了

enter image description here

otsu on it的结果在这里,我只需要一种方法来增强右起第三行的单词:

enter image description here

由于背景较暗而失败的第二种类型

enter image description here

otsu 结果不是很好,因为左边的词看起来像膨胀的词

enter image description here

这是 otsu 正确阈值化的类型,因为没有噪音

enter image description here

最佳答案

尝试使用 cv2.adaptiveThreshold()

enter image description here enter image description here

import cv2

image = cv2.imread("2.png", 0)
adaptive = cv2.adaptiveThreshold(image,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY,11,5)
cv2.imshow("adaptive", adaptive)
cv2.waitKey()

关于python - 使用 python 从不良闪电图像中分割文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58153717/

相关文章:

python - 我可以通过在 Python 中使用这个新手代码运行 time.sleep() 来损坏系统吗?

python - appengine ndb 按种类名称初始化模型

c - tic-tac-toe 使用 opencv 但我可以在识别游戏板时停止

python - 适应不同雷电条件的OpenCV阈值

python - 如何使用 morphologyEx 和 drawContours 检测空的公园空间?

python - 对任意多个字典和数字进行数学运算

python - 如何继承 ABCMeta

c++ - 如何为 OpenCV 找到对象的正确 HSV 阈值?

python - 如何在 Python(不使用 MedPy)或 C 中将 *.mha 文件转换为 *.nii 文件?

matlab - 使用matlab从具有透视失真的图像中进行文本检测