카테고리 없음

Window10+OCR-pytesseract 설치+python

나쁜천사1004 2019. 5. 1. 21:06
반응형

Window10+OCR-pytesseract 설치 방법을 아래와 같이 정리한다.

 

1. OCR 다운로드 및 설치

 - https://github.com/tesseract-ocr/tesseract/wiki/4.0-with-LSTM#400-alpha-for-windows 

 

 다운받은 tesseract-ocr-setup-4.00.00dev.exe 프로그램 실행

  - 다음 버튼 클릭

  - 다음 버튼 클릭

 

2. Window 환경설정

내컴퓨터 > 속성 > 고급 시스템 설정

고급탭 > 환경변수 클릭

아래와 같이 환경변수 팝업화면에서 Path선택 후 편집 클릭

새로 만들기 버튼 크릭 후 C:\Program Files (x86)\Tesseract-OCR\ 등록 후 확인버튼 클릭

 

 pytesseract  TESSDATA_PREFIX 환경변수 저장

환경변수 저장

 

#Python 테스트

from PIL import Image
import pytesseract
import argparse
import cv2
import os
 

# load the example image and convert it to grayscale
image = cv2.imread("test.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = "{}.png".format(os.getpid())
cv2.imwrite(filename, gray)

pytesseract.pytesseract.tesseract_cmd = "C:\\Program Files (x86)\\Tesseract-OCR\\tesseract.exe"


text = pytesseract.image_to_string(Image.open(filename))
os.remove(filename)

print(text)

 

오류 안나면 성공

반응형