简体   繁体   English

如何对图像是否包含文本进行分类?

[英]how to classify if images contain text or not?

I have a lot of images extracted from Search engine, and I am use OCR to perform descent text extraction from these image, but There are images that do not contain text.我有很多从搜索引擎中提取的图像,我正在使用 OCR 从这些图像中执行下降文本提取,但是有些图像不包含文本。

Thus I would like to determine if an image simply contains text or not in python, and if it doesn't, i wouldn't have to perform OCR on it.因此,我想确定图像是否仅包含 python 中的文本,如果没有,我就不必对其执行 OCR。 Ideally this method would have a high recall.理想情况下,这种方法具有很高的召回率。

Use pytteseract.使用 pytteseract。 Something like this:像这样的东西:

from PIL import Image
import pytesseract

def contains_text(image_path):
    text = pytesseract.image_to_string(Image.open(image_path))
    
    if text == "":
        return False # No text detected
    else:
        return text

I do not know of a way to detect that there is no text without trying to perform OCR (like above).我不知道有一种方法可以在不尝试执行 OCR 的情况下检测到没有文本(如上所示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM