wonpick
devvon
wonpick
방문자🌱
오늘
어제
  • 분류 전체보기 (146)
    • 개발 (42)
      • Spark (7)
      • Hadoop (3)
      • ML&DL (4)
      • Paper Review (0)
      • ETC (24)
    • STUDY (77)
      • Data Engineering (54)
      • Cloud (4)
      • Algorithm (5)
      • SQL (10)
      • Toy Project (1)
    • Android (2)
    • Backend (14)
    • 인턴 (0)
    • 공모전 (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

인기 글

태그

  • kodekloud
  • cka
  • 데이터엔지니어링
  • 쿠버네티스
  • 최신 데이터 인프라 이해하기
  • SQL
  • Python
  • 최신 데이터 인프라 이해하기 #7
  • 인턴강연
  • 자연어처리

최근 댓글

최근 글

티스토리

Designed By.hELLO
wonpick

devvon

개발/ETC

[Tesseract-OCR] 이미지에서 원하는 부분만 추출

2021. 5. 10. 12:35

정형화 된 문서이고 심지어 스캔본인데 인식률이 좋지 못하다ㅠㅠ

from os import listdir
from os.path import isfile, join
import numpy
import cv2
import numpy as np
import sys

sys.stdout = open(r'C:\Users\user\Desktop\output.txt','w') #프린트된 출력물을 해당 경로 텍스트 파일로 저장함. a는 이어쓰기이고 w는 덮어쓰기 
mypath=(r'C:\Users\user\Desktop\ocr') #이미지 5장이 들어있는 폴더 경로
onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
images = numpy.empty(len(onlyfiles), dtype=object)

for n in range(0, len(onlyfiles)):
    #images[n] = cv2.imread( join(mypath,onlyfiles[n]) )
    pytesseract.pytesseract.tesseract_cmd = (r'C:\Program Files\Tesseract-OCR\tesseract.exe')
    # 한글 인식률을 높이기 위해 trained data인 kor.traineddata,kor_vert.traineddata 다운 
    # 그 뒤 내 tesseract-ocr > tessdata파일에 이동
    images[n]= pytesseract.image_to_string((Image.open(join(mypath,onlyfiles[n]))), lang="kor")
    #images[n] = (images[n][30:168]) 
    print(("#{}\n{}\n\n".format(n+1,images[n][35:168]))) #인식률이 좋지 못해 최대한 통으로 가져왔다.

#np.savetxt(r'C:\Users\user\Desktop\ output.txt',images,fmt='%s') #이후 리스트만 저장할때
  • trained data 받는 곳
    https://github.com/tesseract-ocr/tessdata
  • 참고 자료(tesseract 설치와 pytesseract 설치)
    https://www.youtube.com/watch?v=rNxMwtottmM&t=13s
  • 정확도 높이기 위해 참고 해볼 자료
    https://github.com/kairess/super_resolution

'개발 > ETC' 카테고리의 다른 글

[python] 폴더 안 . csv 불러오고 1개의 파일로 만들기  (0) 2021.05.10
[python]엄청 큰 csv파일 읽기  (0) 2021.05.10
Unnamed: 0 열 제거하는 방법들 (index)  (0) 2021.05.09
khaiii 설치하기(형태소 분석)  (0) 2021.05.09
네이버 뉴스 정보 가져오기  (0) 2021.05.09
    wonpick
    wonpick

    티스토리툴바