Skip to content

Instantly share code, notes, and snippets.

@priyanlc
Created April 19, 2024 06:37
Show Gist options
  • Save priyanlc/05c4cee417352b7047b6c572668f7131 to your computer and use it in GitHub Desktop.
Save priyanlc/05c4cee417352b7047b6c572668f7131 to your computer and use it in GitHub Desktop.
Delete Images with characters with easyocr
import os
import easyocr
class EasyOCRProcessor:
def __init__(self, languages=None): # Default to Japanese
if languages is None:
languages = ['ja']
self.reader = easyocr.Reader(languages)
def process_image(self, filename):
try:
results = self.reader.readtext(filename, detail=0, paragraph=True)
japanese_text_detected = len(results) > 0
if japanese_text_detected:
os.remove(filename)
return f"Deleted '{filename}' as Japanese text was detected."
else:
return f"Kept '{filename}', no Japanese text detected."
except Exception as e:
return f"Error processing '{filename}': {e}, kept the file."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment