Getting started
1. 환경 설정
소스 코드를 준비합니다 (SaigeEdge submodule 포함).
Python 환경을 생성하고 dependencies를 설치합니다 (Python 3.10+).
conda create -n ocr_edge python=3.10
conda activate ocr_edge
pip install -r requirements/develop.txt
2. 사용
import cv2
from ocr import InferenceHandler
# 세 checkpoint 경로는 필수입니다 — 생략/None 이면 에러입니다. 배포 패키지는 기본 경로를 들고
# 있지 않으므로 쓸 모델을 항상 명시합니다.
config = {
"det_checkpoint_path": "/path/to/det.saigeedge", # DET .saigeedge
"ori_checkpoint_path": "/path/to/ori.saigeedge", # ORI .saigeedge
"rec_checkpoint_path": "/path/to/rec.saigeedge", # REC .saigeedge (ONNX + charset)
"password": None, # 세 checkpoint 공용 AES password (평문 번들이면 None)
}
err_code, err_msg, handler = InferenceHandler.build(config)
image = cv2.imread("path/to/image.jpg", cv2.IMREAD_COLOR)
with handler:
err_code, err_msg, result = handler.infer(image)
for box in result.boxes:
print(box.text, box.confidence, box.polygon)
print(result.stages) # {"det_ms": .., "crop_ms": .., "ori_ms": .., "rec_ms": .., "total_ms": ..}
ROI 폴리곤을 알고 있는 경우 det/ori 를 생략하고 인식만 수행할 수 있습니다 (수동 모드).
runtime option 은 build 후 (model, key, value) 단건 API 로 조정합니다.
각 기능에 대한 설명은 API Reference를 참고하세요.
3. 데모 실행
공식 API 흐름(build → 옵션 조정 → 추론 → 시각화 저장)을 한 번에 보여주는 데모입니다.
이미지별로 polygon / text / confidence / rotation 을 출력하고, 시각화 결과를
demo/output/ 에 저장합니다.
4. CLI 실행
config 기반으로 이미지 디렉터리를 일괄 추론하고 results.json 을 생성합니다.
5. 라이브러리 빌드
배포용으로 cythonize된 라이브러리를 빌드합니다. 예제에서는 deploy/ 폴더를 사용합니다.
빌드 시 tests, demo, config, requirements 등 개발 전용 디렉토리는 자동으로 제외됩니다.