#!/usr/bin/env python3
"""Test OCR on full cell 11"""

import cv2
import os
from google.cloud import vision

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'google-credentials.json'
client = vision.ImageAnnotatorClient()

# Load full cell
cell = cv2.imread('gogoelocroutput/cells/page003_cell11.png')

_, encoded = cv2.imencode('.png', cell)
image = vision.Image(content=encoded.tobytes())
response = client.text_detection(image=image)

if response.text_annotations:
    full_text = response.text_annotations[0].description
    print("Full cell OCR result:")
    print("="*80)
    print(full_text)
    print("="*80)

    # Check if voter ID is in there
    if '৬৮০৩২৩১৬৯৬৬৬' in full_text or '680323169666' in full_text:
        print("\n✓ Voter ID found in full text!")
    else:
        print("\n✗ Voter ID NOT found in full text")
        print("Checking what voter ID text was detected...")
        for annotation in response.text_annotations[1:]:
            if 'নং' in annotation.description or '680' in annotation.description or '৬৮০' in annotation.description:
                print(f"  Found: '{annotation.description}'")
else:
    print("✗ No text detected in full cell!")
