Last active
March 29, 2018 03:30
-
-
Save NeedPainkiller/95923dcaaa475e792e03d376bb0666e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import pytesseract | |
| import win32clipboard | |
| # tesseract commmad 불러오기 | |
| pytesseract.pytesseract.tesseract_cmd = '.\\Tesseract-OCR\\tesseract.exe' | |
| # 결과 텍스트 값 클립보드 저장 | |
| def setClipboard(text): | |
| win32clipboard.OpenClipboard() | |
| win32clipboard.EmptyClipboard() | |
| win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, text) | |
| win32clipboard.CloseClipboard() | |
| def ocrClip(): | |
| im_gray = cv2.imread('temp.png', cv2.IMREAD_GRAYSCALE) | |
| (thresh, im_bw) = cv2.threshold(im_gray, 127, 255, cv2.THRESH_TRUNC | cv2.THRESH_OTSU) | |
| # cv2.imwrite('bw_image.png', im_bw) | |
| text = pytesseract.image_to_string(im_bw, lang='eng', config="-psm 8 -oem 3") | |
| setClipboard(text) | |
| print(text) | |
| ocrClip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment