이 프로젝트는 신분증 및 문서 인식을 위한 고성능 OCR(Optical Character Recognition) AI 모듈입니다. 신분증/운전면허증의 텍스트를 정확하게 인식하기 위한 이미지 전처리, 데이터셋 생성, 그리고 딥러닝 기반 OCR 시스템을 구현합니다.
- 적응형 이미지 강화: CLAHE 기반 대비 강화
- 지능형 기울기 보정: 허프 변환 기반 자동 회전 보정
- 고급 노이즈 제거: 컬러/그레이스케일 이미지 최적화
- 다단계 이진화: 적응형 가우시안/평균 임계값
- 품질 메트릭: 선명도, 대비, 밝기, 노이즈 레벨 자동 측정
- 고품질 인페인팅: OpenCV TELEA/NS 알고리즘 지원
- 자동 품질 평가: 구조적 유사성 기반 점수 계산
- 에러 복구: 강건한 에러 핸들링 및 로깅
- 배치 처리: 다중 이미지 동시 처리 지원
- 실제 데이터 시뮬레이션: Faker 라이브러리 기반 한국어 데이터
- 다양한 변형: 노이즈, 블러, 회전, 밝기 조정
- 자동 어노테이션: YOLO/COCO 형식 라벨 생성
- 대량 생성: 수천 개 샘플 자동 생성
- 실시간 모니터링: CPU, 메모리, GPU 사용량 추적
- 성능 메트릭: 실행 시간, 처리량, 품질 점수
- 자동 리포트: 마크다운 형식 성능 리포트 생성
- 시각화: 성능 트렌드 그래프 자동 생성
- JSON 기반 설정: 모든 매개변수 중앙 관리
- 타입 안전성: 데이터클래스 기반 설정 검증
- 동적 업데이트: 런타임 설정 변경 지원
- YOLO + CRNN 기반 OCR 모델 구현
- 실시간 스트리밍 처리 지원
- 웹 API 인터페이스 개발
- 모바일 최적화 버전
# 저장소 클론
git clone <repository-url>
cd ocr-ai-module
# 가상환경 생성 및 활성화
python -m venv venv
source venv/bin/activate # Linux/Mac
# 또는
venv\Scripts\activate # Windows
# 의존성 설치
pip install -r requirements.txt# 기본 템플릿 생성
python -m app.main --mode template
# 사용자 정의 파일로 템플릿 생성
python -m app.main --mode template --original my_id.png --mask my_mask.png --output my_template.png# 전체 전처리 파이프라인
python -m app.main --mode preprocess --original input_image.png
# 특정 단계만 적용
python -m app.main --mode preprocess --no-rotation --no-binarizationpython -m app.main --mode allfrom app.main import OCRProcessor
from app.preprocess.image_preprocessing import ImagePreprocessor
from app.models.generate_idcard_template import IDCardTemplateGenerator
# OCR 프로세서 초기화
processor = OCRProcessor()
# 템플릿 생성
success = processor.process_template_generation()
# 이미지 전처리
preprocessor = ImagePreprocessor(target_size=(800, 500))
processed_image = preprocessor.preprocess("input.png")
# 품질 메트릭 확인
metrics = preprocessor.get_image_quality_metrics(processed_image)
print(f"이미지 품질: {metrics}")from app.data_generation.synthetic_data_generator import SyntheticIDCardDataGenerator
# 데이터 생성기 초기화
generator = SyntheticIDCardDataGenerator(
template_path="app/dataset/idcard_template.png",
font_path="app/dataset/NanumGothic.ttf"
)
# 1000개 합성 데이터 생성
data = generator.generate_synthetic_data(
num_samples=1000,
output_dir="synthetic_data"
)
# YOLO 어노테이션 생성
generator.generate_annotation_file(data, "annotations.txt", "yolo")from app.utils.benchmark import get_benchmark
# 벤치마크 시스템 초기화
benchmark = get_benchmark()
# 이미지 처리 성능 측정
results = benchmark.benchmark_image_processing(
processor=preprocessor,
image_paths=["image1.png", "image2.png"],
num_iterations=10
)
# 성능 리포트 생성
report_path = benchmark.generate_performance_report()
print(f"성능 리포트: {report_path}")ocr-ai-module/
├── app/
│ ├── __init__.py
│ ├── main.py # 메인 실행 파일
│ ├── models/
│ │ ├── __init__.py
│ │ └── generate_idcard_template.py # 템플릿 생성 모듈
│ ├── preprocess/
│ │ ├── __init__.py
│ │ └── image_preprocessing.py # 이미지 전처리 모듈
│ ├── data_generation/
│ │ ├── __init__.py
│ │ └── synthetic_data_generator.py # 합성 데이터 생성
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── config.py # 설정 관리
│ │ ├── benchmark.py # 성능 벤치마킹
│ │ └── image_checker.py # 이미지 품질 검증
│ ├── dataset/ # 데이터셋 디렉토리
│ └── output/ # 출력 디렉토리
├── requirements.txt # 의존성 목록
├── config.json # 설정 파일 (선택사항)
└── README.md
{
"preprocessing": {
"target_width": 800,
"target_height": 500,
"apply_rotation_correction": true,
"apply_enhancement": true,
"angle_threshold": 2.0,
"adaptive_threshold_method": "gaussian"
},
"template_generation": {
"inpaint_radius": 3,
"inpaint_method": "telea",
"quality_threshold": 0.5
},
"data_generation": {
"num_samples": 1000,
"font_size_range": [20, 40],
"noise_level": 0.1
}
}from app.utils.config import get_config_manager
config_manager = get_config_manager()
config_manager.update_config(use_gpu=True, num_workers=8)
config_manager.save_config()- CPU: 멀티코어 프로세서 권장
- 메모리: 최소 8GB RAM
- GPU: CUDA 지원 GPU (선택사항)
- 저장공간: 최소 2GB 여유 공간
- GPU 가속: CUDA 지원 OpenCV 설치
- 메모리 최적화: 배치 크기 조정
- 병렬 처리:
num_workers설정 조정 - 캐싱: 전처리된 이미지 캐시 활용
# 코드 포맷팅
black app/
# 린팅
flake8 app/
# 테스트 실행
pytest tests/from app.utils.benchmark import benchmark
@benchmark("custom_function")
def my_function():
# 성능을 측정할 함수
pass- 평균 처리 시간: ~0.15초/이미지
- 메모리 사용량: ~50MB
- 처리량: ~6.7 이미지/초
- 평균 생성 시간: ~0.8초
- 품질 점수: 0.85/1.0
- 메모리 효율성: 95%
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
이 프로젝트는 MIT 라이선스 하에 배포됩니다. 자세한 내용은 LICENSE 파일을 참조하세요.
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: [email protected]
- OpenCV 커뮤니티
- scikit-image 개발팀
- Faker 라이브러리 기여자들
- 모든 오픈소스 기여자들
⭐ 이 프로젝트가 도움이 되었다면 Star를 눌러주세요!