How to check if a image has any text or not?

Question:

I’m looking for a simple solution that would return a boolean if ANY kind of English text is present in an image file. I wish to use this to detect memes. For example, the following file should be detected as an image with text.

https://i.pinimg.com/originals/d5/13/4b/d5134b891d3903d0f272f6430014f089.gif

I’ve come across elaborate machine learning techniques using OpenCV but I haven’t been able to fully implement it. Is there any quicker, simpler, and just as effective solution for this?

I look forward to your valuable feedback!

Asked By: Nice Guy

||

Answers:

There is indeed simple way with opencv and pytessaract after installing you will only need to use a few lines in order to get the text

pip install opencv-python

pip install pytesseract

import cv2
import pytesseract

img = cv2.imread('yourimage.jpeg')   

text = pytesseract.image_to_string(img)

Read Text from Image with One Line of Python Code

Also if you don’t like the first way you can use Google vision, keep in mind it will return Json and you will extract what you need.

https://cloud.google.com/vision/docs/ocr

Python Client for Google Cloud Vision

Answered By: InUser

We can use pytesseract python package for get text form the images. You can easily install like pip install pytesseract

Here is the example code:

import cv2
import pytesseract
image = cv2.imread('test.jpeg')
text = pytesseract.image_to_string(image)
print(text)

Here is my sample image
enter image description here

So, the output should be like

IS BITCOIN
GOING TO
$20.000
BY CHRISTMAS?
Answered By: Karthick Nagarajan

You can use OpenCV and pytesseract to perform your task.

import cv2
import pytesseract
img = cv2.imread('YOUR_IMAGE_PATH')
text = pytesseract.image_to_string(img)
print(text)
Answered By: Ransaka Ravihara
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.