1. Tesseract OCR 설치
https://github.com/UB-Mannheim/tesseract/wiki
Home
Tesseract Open Source OCR Engine (main repository) - UB-Mannheim/tesseract
github.com
위 링크로 접속하여 빨간색으로 표시된 파일을 다운로드하고 실행하여 Tesseract OCR을 설치합니다.
2. 한국어 인식을 위한 훈련 데이터 받기
https://github.com/tesseract-ocr/tessdata/raw/main/kor.traineddata
tessdata/kor.traineddata at main · tesseract-ocr/tessdata
Trained models with fast variant of the "best" LSTM models + legacy models - tesseract-ocr/tessdata
github.com
위 링크에 접속하여 다운로드한 파일을 Tesseract OCR 설치 경로 안의 tessdata폴더 안에 넣어줍니다.
3. Tesseract OCR 설치 경로를 PATH에 등록합니다.
기본 설치 경로 : C:\Program Files\Tesseract-OCR
PATH 등록 방법에 대한 자세한 내용은 여기를 참고해 주세요
4. PyTesseract 설치
$ pip install pytesseract
5. 샘플 코드
import pytesseract
from PIL import ImageGrab
def extract_text_from_screen():
screenshot = ImageGrab.grab()
text = pytesseract.image_to_string(screenshot, lang='kor+eng') # 인식 언어를 한국어와 영어로 설정
return text
if __name__ == "__main__":
print(extract_text_from_screen())
스크린샷을 찍어서 화면에 있는 글자를 모두 읽어오는 코드이다.
screenshot대신에 저장되어 있는 사진 파일을 파라미터로 사용해도 된다.
반응형
'코딩 > Python' 카테고리의 다른 글
[Python] 실행중인 프로세스 확인하기 (2) | 2023.12.09 |
---|---|
[Python] 투네이션 위젯 알림 파이썬으로 가져오기 (0) | 2022.09.11 |
[Python] py 파일을 exe로 변환하기 (0) | 2022.09.11 |
[Python] 관리자 권한 요청하기 (1) | 2022.09.11 |
파이썬 설치하기 (0) | 2022.09.10 |