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

import cv2
import os
from google.cloud import vision

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

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

_, encoded = cv2.imencode('.png', cell)
content = encoded.tobytes()

image = vision.Image(content=content)
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:
        print("\n✓ Voter ID found in full text!")
    else:
        print("\n✗ Voter ID NOT found in full text")

    # Show all detected text blocks
    print(f"\nTotal text blocks detected: {len(response.text_annotations)}")
    for i, annotation in enumerate(response.text_annotations[1:11], 1):  # First 10 blocks
        vertices = [(v.x, v.y) for v in annotation.bounding_poly.vertices]
        print(f"  Block {i}: '{annotation.description}' at {vertices[0]}")
else:
    print("✗ No text detected in full cell!")
