File size: 1,586 Bytes
1a7ee60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
"""
Test EasyOCR initialization and functionality
"""

# Fix for TensorFlow mutex warnings on macOS
import os
os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

import warnings
warnings.filterwarnings('ignore')

import sys
import numpy as np
import cv2

print("Testing EasyOCR integration...")
print("=" * 60)

try:
    from ocr_engine import LightweightOCR
    
    print("\n1. Importing LightweightOCR... ✓")
    
    print("\n2. Initializing EasyOCR engine...")
    ocr = LightweightOCR(lang='en', use_gpu=False)
    print("   ✓ EasyOCR initialized successfully!")
    
    print("\n3. Creating dummy image for testing...")
    # Create a white image with black text "Hello World"
    image = np.ones((100, 300, 3), dtype=np.uint8) * 255
    cv2.putText(image, 'Hello World', (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
    print("   ✓ Dummy image created")
    
    print("\n4. Running OCR extraction...")
    result = ocr.extract_text(image)
    print(f"   ✓ Extraction complete!")
    print(f"   Extracted text: '{result['text']}'")
    
    if "Hello" in result['text'] or "World" in result['text']:
        print("   ✓ Text verification passed!")
    else:
        print("   ⚠ Text verification warning: Expected 'Hello World', got something else")
    
    print("\n" + "=" * 60)
    print("✅ ALL TESTS PASSED!")
    print("=" * 60)
    
except Exception as e:
    print(f"\n❌ ERROR: {str(e)}")
    import traceback
    traceback.print_exc()
    sys.exit(1)