Files
AX-Copilot-Codex/dist/AxCopilot/skills/ocr-extract.skill.md
lacvet a027ea4f9a
Some checks failed
Release Gate / gate (push) Has been cancelled
재구성 AX Agent 설정과 채팅 UI를 Claude형 구조로
2026-04-04 17:48:51 +09:00

119 lines
3.3 KiB
Markdown

---
name: ocr-extract
label: OCR 텍스트 추출
description: Python pytesseract를 사용하여 이미지/스캔 문서에서 텍스트를 추출합니다.
icon: \uE8D4
allowed-tools:
- file_read
- file_write
- process
- image_analyze
- text_summarize
tabs: cowork
---
이미지 또는 스캔된 문서에서 텍스트를 추출하세요.
## 실행 경로 선택 (Python 가능/불가)
- 먼저 `process``python --version`을 확인하세요.
- Python 가능: 기존 pytesseract 경로를 사용하세요.
- Python 불가: `image_analyze`로 텍스트 후보를 추출하고 `text_summarize` + `file_write`로 정제본을 제공하세요.
## 사전 준비
1. Tesseract OCR 엔진이 시스템에 설치되어 있어야 합니다.
- Windows: https://github.com/UB-Mannheim/tesseract/wiki 에서 설치
- 한국어 지원: 설치 시 "Korean" 언어 데이터 선택
2. Python 패키지 설치:
```
process: pip install pytesseract Pillow
```
## 작업 절차
1. **이미지 확인**: 사용자가 제공한 이미지 파일 확인
2. **전처리 (선택)**: 이미지 품질이 낮으면 전처리 스크립트 적용
3. **OCR 실행**: pytesseract로 텍스트 추출
4. **결과 저장**: 추출된 텍스트를 파일로 저장하고 사용자에게 안내
## OCR 스크립트 템플릿
### 기본 텍스트 추출
```python
import pytesseract
from PIL import Image
# Windows에서 Tesseract 경로 지정 (필요 시)
# pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
img = Image.open('scan.png')
text = pytesseract.image_to_string(img, lang='kor+eng')
print(text)
with open('extracted.txt', 'w', encoding='utf-8') as f:
f.write(text)
```
### 이미지 전처리 (품질 개선)
```python
from PIL import Image, ImageFilter, ImageEnhance
img = Image.open('scan.png')
# 그레이스케일 변환
img = img.convert('L')
# 대비 향상
enhancer = ImageEnhance.Contrast(img)
img = enhancer.enhance(2.0)
# 선명도 향상
img = img.filter(ImageFilter.SHARPEN)
# 이진화 (흑백)
threshold = 128
img = img.point(lambda x: 255 if x > threshold else 0)
img.save('preprocessed.png')
text = pytesseract.image_to_string(img, lang='kor+eng')
```
### 배치 OCR (여러 이미지)
```python
import glob
import pytesseract
from PIL import Image
results = []
for path in sorted(glob.glob('*.png')):
img = Image.open(path)
text = pytesseract.image_to_string(img, lang='kor+eng')
results.append(f'--- {path} ---\n{text}\n')
with open('all_extracted.txt', 'w', encoding='utf-8') as f:
f.write('\n'.join(results))
```
### 표 영역 추출
```python
import pytesseract
from PIL import Image
img = Image.open('table.png')
# TSV 형식으로 추출 (표 구조 보존)
tsv_data = pytesseract.image_to_data(img, lang='kor+eng', output_type=pytesseract.Output.DATAFRAME)
print(tsv_data)
```
## 지원 언어
- `kor` — 한국어
- `eng` — 영어
- `kor+eng` — 한국어+영어 혼합 (권장)
- `jpn` — 일본어
- `chi_sim` — 중국어 간체
## 팁
- 스캔 해상도 300dpi 이상이면 인식률이 높습니다
- 기울어진 이미지는 `img.rotate()` 로 보정 후 추출하세요
- 손글씨는 인식률이 낮을 수 있습니다
한국어로 안내하세요. 작업 폴더에 Python 스크립트와 결과 파일을 저장하세요.