Check if extracted text is meaningful (not gibberish).
(text)
| 696 | |
| 697 | |
| 698 | def is_meaningful_text(text): |
| 699 | """Check if extracted text is meaningful (not gibberish).""" |
| 700 | if not text or len(text) < 2: # Ignore empty or single-character text |
| 701 | return False |
| 702 | # Allow only words with letters, numbers, or common symbols |
| 703 | return bool(re.search(r"[a-zA-Z0-9]", text)) |
| 704 | |
| 705 | |
| 706 | def extract_text(image, processor, model): |