Prepares the image to improve OCR accuracy.
(image)
| 721 | |
| 722 | |
| 723 | def enhance_image_for_ocr(image): |
| 724 | """Prepares the image to improve OCR accuracy.""" |
| 725 | # Convert to grayscale |
| 726 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
| 727 | |
| 728 | # Apply adaptive histogram equalization to enhance contrast |
| 729 | clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8, 8)) |
| 730 | enhanced = clahe.apply(gray) |
| 731 | |
| 732 | # Resize to a standard size (helps OCR model generalize better) |
| 733 | resized = cv2.resize(enhanced, (512, 512)) |
| 734 | |
| 735 | return resized |
| 736 | |
| 737 | |
| 738 | def detect_text(image): |