image - 如何从任何消费产品的图像中检测文本/徽标细节?
问题描述
我正在尝试从包装图像中检测任何消费品的名称。例如- Maggie(我想检测- Maggie 的幸福是自制的)Kellogg's
我尝试过应用图像预处理(例如腐蚀、打开、关闭等),然后将该预处理图像提供给 pytesseract(OCR)。如果可以提供任何帮助,我打算使用 Image-Magic 工具。
仅对图像进行预处理就足够了,如果没有,那我该怎么办?(任何代码,软件任何东西)
PS-我不想使用 Google Vision 或任何类似的 API
解决方案
在 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
推荐阅读
- python - 如何用类调用替换嵌套函数
- ansible - 如何使用我的 ansible playbook 中的事实选择变量?
- java - 递归调用中的执行顺序
- python - 如何将值转移到txt文件的下一行
- git - 在不属于我的子模块中推送更改
- python - 如何将一个参数传递给 argparse 会影响两个选项?
- django - 图像文件不再出现在生产中如何解决问题
- javascript - 我如何将参数放入 IMG SRC
- python - 使用 Snakemake 从目录中丢失输入文件
- python - Pandas Boolean Where Filtering:如何使用它来创建数据的真实子集?