100 lines
2.8 KiB
Python
100 lines
2.8 KiB
Python
"""
|
|
Quick test to verify PaddleOCRVL integration works
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
os.environ["PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK"] = "True"
|
|
|
|
# Test imports
|
|
print("="*80)
|
|
print("Testing PaddleOCRVL Integration")
|
|
print("="*80)
|
|
|
|
try:
|
|
from paddleocr import PaddleOCRVL, SealTextDetection, TextRecognition
|
|
print("[OK] PaddleOCRVL import successful")
|
|
except ImportError as e:
|
|
print(f"[FAIL] Import failed: {e}")
|
|
sys.exit(1)
|
|
|
|
# Test model creation
|
|
print("\nInitializing PaddleOCRVL...")
|
|
try:
|
|
pipeline = PaddleOCRVL(
|
|
use_seal_recognition=True,
|
|
use_ocr_for_image_block=True,
|
|
use_layout_detection=True
|
|
)
|
|
|
|
if pipeline is None:
|
|
print("[FAIL] PaddleOCRVL initialization returned None")
|
|
sys.exit(1)
|
|
|
|
print("[OK] PaddleOCRVL initialized successfully")
|
|
except Exception as e:
|
|
print(f"[FAIL] Initialization failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|
|
|
|
# Test on a simple image
|
|
print("\nTesting prediction...")
|
|
unwarp_path = r"test_reports_full\WTS2025-21283.pdf\seal_unwarp_0.png"
|
|
|
|
if not os.path.exists(unwarp_path):
|
|
print(f"[FAIL] Test image not found: {unwarp_path}")
|
|
sys.exit(1)
|
|
|
|
try:
|
|
output = pipeline.predict(unwarp_path)
|
|
|
|
if output and len(output) > 0:
|
|
res = output[0]
|
|
|
|
# Save and read JSON
|
|
import json
|
|
from pathlib import Path
|
|
temp_dir = Path("temp_test")
|
|
temp_dir.mkdir(exist_ok=True)
|
|
|
|
res.save_to_json(save_path=str(temp_dir))
|
|
|
|
json_file = temp_dir / "seal_unwarp_0_res.json"
|
|
if json_file.exists():
|
|
with open(json_file, 'r', encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
|
|
# Find seal text
|
|
for block in data.get('parsing_res_list', []):
|
|
if block.get('block_label') == 'seal':
|
|
text = block.get('block_content', '')
|
|
print(f"[OK] Recognition successful: '{text}'")
|
|
|
|
# Verify result
|
|
if "威凯检测技术有限公司" in text:
|
|
print("[OK] Result is CORRECT!")
|
|
else:
|
|
print(f"[WARN] Result may be incorrect (expected: 威凯检测技术有限公司)")
|
|
|
|
# Cleanup
|
|
import shutil
|
|
shutil.rmtree(temp_dir, ignore_errors=True)
|
|
|
|
print("\n" + "="*80)
|
|
print("All tests passed!")
|
|
print("="*80)
|
|
sys.exit(0)
|
|
|
|
print("[FAIL] Failed to read JSON result")
|
|
sys.exit(1)
|
|
else:
|
|
print("[FAIL] No output from prediction")
|
|
sys.exit(1)
|
|
|
|
except Exception as e:
|
|
print(f"[FAIL] Prediction failed: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|