首页 > 解决方案 > 如何从任何消费产品的图像中检测文本/徽标细节?

问题描述

我正在尝试从包装图像中检测任何消费品的名称。例如- Maggie(我想检测- Maggie 的幸福是自制的)Kellogg's

我尝试过应用图像预处理(例如腐蚀、打开、关闭等),然后将该预处理图像提供给 pytesseract(OCR)。如果可以提供任何帮助,我打算使用 Image-Magic 工具。

仅对图像进行预处理就足够了,如果没有,那我该怎么办?(任何代码,软件任何东西)

PS-我不想使用 Google Vision 或任何类似的 API

标签: imageimagemagicktext-recognitionpython-tesseract

解决方案


在 Imagemagick 6 中,您可以执行以下操作来隔离“kelloggs”。

fill back to replace everything but the red color
fill white to replace the red color

convert kellogg.jpg -fuzz 15% \
-fill black +opaque "rgb(240,0,0)" \
-fill white -opaque "rgb(240,0,0)" \
result.png


在此处输入图像描述

对于您的“maggie”图像,它有点复杂,因为“maggie”的黄色和其他地方的黄色。

fill yellow color to replace the white in the corners
fill yellow color to replace black
floodfill the outside yellow with black
fill black to replace everything but yellow
fill white to replace yellow

convert maggie.jpg \
-fuzz 15% -fill "rgb(254,242,0)" -opaque white \
-fuzz 20% -fill "rgb(254,242,0)" -opaque black \
-fuzz 15% -fill black -draw "color 10,10 floodfill" -alpha off \
-fuzz 15% -fill black +opaque "rgb(254,242,0)" \
-fuzz 15% -fill white -opaque "rgb(254,242,0)" \
result2.png


在此处输入图像描述

但是留下了商标。因此,要删除它,我们添加连接组件处理以过滤掉最小的白色区域。

convert maggie.jpg \
-fuzz 15% -fill "rgb(254,242,0)" -opaque white \
-fuzz 20% -fill "rgb(254,242,0)" -opaque black \
-fuzz 15% -fill black -draw "color 10,10 floodfill" -alpha off \
-fuzz 15% -fill black +opaque "rgb(254,242,0)" \
-fuzz 15% -fill white -opaque "rgb(254,242,0)" \
-define connected-components:area-threshold=50 \
-define connected-components:mean-color=true \
-connected-components 4 \
result3.png


在此处输入图像描述


推荐阅读