66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
import os
|
|
import cv2
|
|
import fastdeploy as fd
|
|
import numpy as np
|
|
|
|
def test_fastdeploy_ocr():
|
|
print("FastDeploy 버전:", fd.__version__)
|
|
|
|
# 모델 경로 설정
|
|
det_model_file = "modules/PP_Models/det/inference.pdmodel"
|
|
det_params_file = "modules/PP_Models/det/inference.pdiparams"
|
|
rec_model_file = "modules/PP_Models/rec/inference.pdmodel"
|
|
rec_params_file = "modules/PP_Models/rec/inference.pdiparams"
|
|
rec_label_file = "modules/PP_Models/rec/ppocr_keys_v1.txt"
|
|
cls_model_file = "modules/PP_Models/cls/inference.pdmodel"
|
|
cls_params_file = "modules/PP_Models/cls/inference.pdiparams"
|
|
|
|
try:
|
|
# Runtime 설정
|
|
runtime_option = fd.RuntimeOption()
|
|
runtime_option.use_gpu()
|
|
|
|
print("모델 로딩 중...")
|
|
|
|
# Detection 모델
|
|
det_model = fd.vision.ocr.DBDetector(
|
|
det_model_file, det_params_file, runtime_option=runtime_option
|
|
)
|
|
print("✓ Detection 모델 로딩 완료")
|
|
|
|
# Recognition 모델
|
|
rec_model = fd.vision.ocr.Recognizer(
|
|
rec_model_file, rec_params_file, rec_label_file, runtime_option=runtime_option
|
|
)
|
|
print("✓ Recognition 모델 로딩 완료")
|
|
|
|
# Angle Classifier(optional)
|
|
cls_model = None
|
|
if os.path.isfile(cls_model_file):
|
|
cls_model = fd.vision.ocr.Classifier(
|
|
cls_model_file,
|
|
cls_params_file,
|
|
runtime_option=runtime_option
|
|
)
|
|
|
|
|
|
# 테스트 이미지 로딩
|
|
image_path = "img/1.jpg"
|
|
image = cv2.imread(image_path)
|
|
if image is None:
|
|
raise Exception(f"이미지를 읽을 수 없습니다: {image_path}")
|
|
print(f"✓ 이미지 로딩 완료: {image.shape}")
|
|
|
|
ocr_system = fd.vision.ocr.PPOCRv3(det_model, cls_model, rec_model)
|
|
ocr_result = ocr_system.predict(image)
|
|
print(f"ocr_result: {ocr_result}")
|
|
|
|
print("\n🎉 FastDeploy OCR 테스트 성공!")
|
|
|
|
except Exception as e:
|
|
print(f"❌ 오류 발생: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
test_fastdeploy_ocr() |