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.
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!
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.
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)
So, the output should be like
IS BITCOIN
GOING TO
$20.000
BY CHRISTMAS?
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)
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.
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!
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.
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)
So, the output should be like
IS BITCOIN
GOING TO
$20.000
BY CHRISTMAS?
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)