mirror of
https://github.com/csd4ni3l/grass_touching_captcha.git
synced 2025-11-05 02:58:10 +01:00
13 lines
557 B
Python
13 lines
557 B
Python
import easyocr, difflib, random, string
|
|
from constants import OCR_CHALLENGE_LENGTH
|
|
|
|
reader = easyocr.Reader(['en'])
|
|
|
|
def check_text_similarity(image_path, text):
|
|
result = reader.readtext(image_path, allowlist=string.ascii_letters + string.digits)
|
|
image_text = ''.join([text[1] for text in result]).lower()
|
|
similarity = difflib.SequenceMatcher(None, text, image_text).ratio()
|
|
return image_text, similarity
|
|
|
|
def generate_challenge(username):
|
|
return f"{username} {''.join([str(random.randint(0, 10)) for _ in range(OCR_CHALLENGE_LENGTH)])}" |