【问题标题】:How to detect text shadow如何检测文字阴影
【发布时间】:2016-11-08 05:25:52
【问题描述】:

我正在尝试检测图像中具有阴影效果的文本。背景、文字颜色、文字大小不固定。

这个方法我试过了:

  1. 添加阈值以从类似于矩形的文本中获取形状。
  2. 查找矩形轮廓。

但它不能按我的意愿工作,因为我的图像有不同的背景、字体和文本大小。

什么方法最适合带有阴影检测的文本?

【问题讨论】:

    标签: python opencv image-processing


    【解决方案1】:

    此区域中的所有文本都有一种颜色。您可以计算每种颜色的像素数并对该列表进行排序。文本的颜色将位于此列表的底部。当文本的颜色已知时,您可以更准确地设置阈值。

    def get_count(pixels_in_this_area):
        count = defaultdict(int)
        for pixel_color in pixels_in_this_area:
            count[pixel_color] += 1
    
    count_with_text = get_count(area_with_text)
    count_without_text = get_count(area_without_text)
    for color in count_without_text.keys():
        if color in count_with_text:
            count_with_text[color] -= count_without_text[color]
    
    count_list = list(count_with_text.items())
    count_list.sort(key=lambda: x[1])  # sort by count of pixel with this color
    text_color = count_list[-1][0]
    

    【讨论】:

    • 感谢您的回复。您确定最后一个计数条目应该返回文本颜色吗?因为对我来说只返回随机背景颜色。
    • 尽量只使用不同的背景和文本区域。
    • 我忘了说:这些区域必须具有相同的大小。否则,您需要将“计数”标准化为大小。我很乐意提供帮助)
    猜你喜欢
    • 2012-09-21
    • 2021-09-28
    • 2011-08-11
    • 1970-01-01
    • 2019-12-20
    • 2017-02-27
    • 2018-09-10
    • 2015-12-06
    • 1970-01-01
    相关资源
    最近更新 更多