๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐™‹๐™ฎ๐™ฉ๐™๐™ค๐™ฃ/๐˜ผ๐™‹๐™„

ํŒŒ์ด์ฌ ๊ฐ์ข… OCR ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ๋ฐ ๋„ค์ด๋ฒ„ ํด๋ผ์šฐ๋“œ AI OCR ์‚ฌ์šฉ๋ฒ• (1)

by beomcoder 2023. 3. 30.
728x90
๋ฐ˜์‘ํ˜•

์œ ํ•ด์ด๋ฏธ์ง€๋ฅผ ํŒ๋ณ„ํ•ด์•ผํ•˜๋Š”๋ฐ

์ฒ˜์Œ์—๋Š” ์•ผํ•œ์ด๋ฏธ์ง€๋‚˜ ์ž”์ธํ•œ์ด๋ฏธ์ง€๋ฅผ ํŒ๋ณ„ํ•˜๋Š” ๋ชจ๋ธ์„ ๋งŒ๋“ค์—ˆ์—ˆ๋‹ค.

 

๋งŒ๋“ค๊ณ ๋‚˜์„œ  ์–ดํ”Œ ๋‚ด์—์„œ ์ด์ „์˜ ๊ด‘๊ณ ๋กœ ํŒ๋‹จ๋˜์–ด

์‚ญ์ œ๋˜์—ˆ๋˜ ์ด๋ฏธ์ง€๋ฅผ ๊ฐ€์ง€๊ณ  ์™€์„œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด์•˜๋‹ค.

์–ดํ”Œ ๋‚ด์—์„œ ๊ด‘๊ณ ํ•˜๋Š” ์ด๋ฏธ์ง€

ํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ ์–ดํ”Œ์—์„œ๋Š” ๊ทธ๋Ÿฐ ๊ฒฝ์šฐ๋Š” ๋งŽ์ด ์—†๊ณ  ๊ธ€์ž๋กœ ๊ด‘๊ณ ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์•˜๋‹ค.

๊ทธ๋ž˜์„œ ์šฐ์„  ๊ธ€์ž๋กœ ๊ด‘๊ณ ํ•˜๋Š” ๊ฒŒ์‹œ๋ฌผ์„ ์žก๋Š” ๋กœ์ง์„ ๊ฑฐ์น˜๋ ค๊ณ  ํ•œ๋‹ค.

 

๋‚ด๊ฐ€ ์ƒ๊ฐํ•œ ๋ฐฉ๋ฒ•์€ ๋จผ์ € OCR์„ ํ†ตํ•ด์„œ ๊ธ€์ž๋ฅผ ์ถ”์ถœํ•˜๊ณ  ๊ธ€์ž๊ฐ€ ์žˆ๋‹ค๋ฉด

ํ˜•ํƒœ์†Œ ๋ถ„์„์„ ํ†ตํ•ด ํ‚ค์›Œ๋“œ๋ฅผ ์ถ”์ถœํ•˜์—ฌ ๋กœ์ง์„ ํ†ตํ•ด ๊ด‘๊ณ ์„ฑ ๊ธ€์ด ๋“ค์–ด๊ฐ”๋Š”์ง€ ํŒ๋ณ„ํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์ด๋‹ค.

๋‚ด๊ฐ€ ์ƒ๊ฐํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์ธ๋ฐ ์šฐ์„  ์œ ํ•ด์ด๋ฏธ์ง€์— ๋Œ€ํ•ด ์ •์˜ํ•˜์˜€๊ณ  ๋ฌด๋ฃŒ OCR๋ฅผ ๋จผ์ € ์‚ฌ์šฉํ•ด๋ณด์•˜๋‹ค.

 

1. tesseract

 

tesseract๋Š” ๊ฒ€์ƒ‰ํ–ˆ์„๋•Œ ๊ฐ€์žฅ ๋จผ์ € ๋‚˜์˜จ ํŒŒ์ด์ฌ OCR ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์˜€๋‹ค.

 

pip install pytesseract

๋จผ์ € ํ…Œ์„œ๋ ‰ํŠธ๋ฅผ installํ•˜์—ฌ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋‚˜์™”๋‹ค.

import pytesseract
import numpy as np
from PIL import Image

def image2text(filename):
    image = np.array(Image.open(filename))
    return pytesseract.image_to_string(image)
   
print(image2text('test.png'))
pytesseract.pytesseract.TesseractNotFoundError: tesseract is not installed or it's not in your PATH. See README file for more information.

์™œ ์•ˆ๋ ๊นŒ ๋˜ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๋ณด๋‹ˆ ๊ทธ๋ƒฅ ๋ชจ๋“ˆ๋งŒ pip๋กœ ๋‹ค์šด๋กœ๋“œํ•˜๋ฉด ์•ˆ๋˜๊ณ  ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋‹ค์šด๋ฐ›์•„์•ผ ํ•œ๋‹ค๊ณ  ํ•œ๋‹ค.

 

 

Home

Tesseract Open Source OCR Engine (main repository) - UB-Mannheim/tesseract

github.com

์—ฌ๊ธฐ์„œ ์œˆ๋„์šฐ ๋ฒ„์ „์„ ๋‹ค์šด๋กœ๋“œ๋ฐ›๊ณ  ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ๋‹ค์‹œ ํ•ด๋ณด์•˜๋‹ค.

import numpy as np
import pytesseract
from PIL import Image

def image2text(filename):
    image = np.array(Image.open(filename))
    pytesseract.pytesseract.tesseract_cmd = R'C:\\Program Files\\Tesseract-OCR\\\tesseract'
    return pytesseract.image_to_string(image)
    
print(image2text('test.png'))

"""
| ego 12) vipat &

hitpe://bem2 set
"""

๊ทธ๋Ÿฐ๋ฐ ํ•œ๊ธ€๋„ ์ „๋ถ€ ์˜์–ด๋กœ ์ธ์‹ํ•˜๊ณ  ์ธ์‹๋ฅ ์—๋„ ๋ฌธ์ œ๊ฐ€ ์žˆ์—ˆ๋‹ค.

๊ทธ๋ž˜๋„ ํ•œ๊ธ€๋„ ์ธ์‹์„ ํ•ด๋ด์•ผํ•ด์„œ

return pytesseract.image_to_string(image, lang='kor')

lang์„ ์ถ”๊ฐ€ํ•˜์—ฌ์„œ ์‹คํ–‰ํ•ด๋ณด์•˜๋Š”๋ฐ ์ด๋ฒˆ์—๋Š” ํ•œ๊ธ€์ด ์—†๋‹ค๊ณ  ์—๋Ÿฌ๊ฐ€ ๋‚˜์™”๋‹ค.

pytesseract.pytesseract.TesseractError: (1, 'Error opening data file C:\\Program Files\\Tesseract-OCR/tessdata/kor.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" 
directory. Failed loading language \'kor\' Error opening data file /home/debian/src/github/tesseract-ocr/tesseract/bin/ndebug/x86_64-w64-mingw32-5.0.0-alpha.20210506/usr/x86_64-w64-mingw32/share/tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory. Failed loading language \'eng\' Tesseract couldn\'t load any languages! Could not initialize tesseract.')

๋˜ ๊ฒ€์ƒ‰์„ ํ†ตํ•ด์„œ kor ๋ฒ„์ „์ด ์—†๋‹ค๊ณ  ์•Œ๊ฒŒ ๋˜์—ˆ๊ณ , github์—์„œ ๋‹ค์šด๋กœ๋“œํ–ˆ๋‹ค.

 

GitHub - tesseract-ocr/tessdata: Trained models with support for legacy and LSTM OCR engine

Trained models with support for legacy and LSTM OCR engine - GitHub - tesseract-ocr/tessdata: Trained models with support for legacy and LSTM OCR engine

github.com

๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ณ  kor ๋ฒ„์ „์„ ์ถ”๊ฐ€์‹œ์ผœ์ฃผ์—ˆ๋‹ค.

import numpy as np
import pytesseract
from PIL import Image

def image2text(filename):
    image = np.array(Image.open(filename))
    pytesseract.pytesseract.tesseract_cmd = R'C:\\Program Files\\Tesseract-OCR\\\tesseract'
    return pytesseract.image_to_string(image, lang='kor+eng')

print(image2text('test.png'))
"""
. ๋ฉˆ๊ณ„7๋ฌด182 20์—ฌ๋น„์Šค

1ํƒ•์–ธ์—ฌ์•„
"""

์ง„์งœ ํž˜๋“ค๊ฒŒ ์ฐพ์•„๊ฐ€๋ฉด์„œ ํ–ˆ๋Š”๋ฐ ์ œ๋Œ€๋กœ ๋‚˜์˜ค๋Š”๊ฒŒ ์—†์–ด์„œ ํ—ˆํƒˆํ–ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋‹ค๋ฅธ ocr์„ ์ฐพ์•„๋ณด์•˜๋Š”๋ฐ easyocr์ด๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ฐพ์•˜๋‹ค.

ํ•˜์ง€๋งŒ ์ด๊ฑด ๋ฒ„์ „๋ฌธ์ œ์™€ ๊ธฐํƒ€ ์—๋Ÿฌ๋กœ ์ธํ•ด ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋‹ค.

 

2. NAVER CLOUD OCR

 

NAVER CLOUD PLATFORM

cloud computing services for corporations, IaaS, PaaS, SaaS, with Global region and Security Technology Certification

www.ncloud.com

 

๋„ค์ด๋ฒ„์—์„œ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด์•˜๋”๋‹ˆ ์ž˜๋˜์„œ ์‚ฌ์šฉํ•ด๋ณด์•„์•ผ๊ฒ ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.

๊ฒฐ๋ก ๋ถ€ํ„ฐ ๋งํ•˜๋ฉด ๊ต‰์žฅํžˆ ์“ฐ๊ธฐ ๊ท€์ฐฎ๊ฒŒ ๋งŒ๋“ค์–ด๋†“์•˜๊ณ , API์™€ AI๊ธฐ๋Šฅ์„ ๋ถ„๋ฆฌ์‹œ์ผœ๋†“์•„์„œ

์š”๊ธˆ์„ ๋ถ„์‚ฐ์‹œ์ผœ๋†“์•„์„œ ๊ณ„์‚ฐ์ด ์ž˜ ์•ˆ๋˜๊ฒŒ ํ•ด๋†“์•˜๋‹ค.

 

๋จผ์ € ์ด์šฉ์‹ ์ฒญํ•˜๊ธฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด ์ฝ˜์†”๋กœ ๊ฐ€์ง„๋‹ค.

 

๋„ˆ๋ฌด ๋‚ด์šฉ์ด ๊ธธ์–ด์ ธ์„œ (2)์—์„œ ๊ณ„์† ์“ฐ๋ ค๊ณ  ํ•œ๋‹ค.

 

ํŒŒ์ด์ฌ ๊ฐ์ข… OCR ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ๋ฐ ๋„ค์ด๋ฒ„ ํด๋ผ์šฐ๋“œ AI OCR ์‚ฌ์šฉ๋ฒ• (2)

ํŒŒ์ด์ฌ ๊ฐ์ข… OCR ์‚ฌ์šฉํ•ด๋ณด๊ธฐ ๋ฐ ๋„ค์ด๋ฒ„ ํด๋ผ์šฐ๋“œ AI OCR ์‚ฌ์šฉ๋ฒ• (1) ์œ ํ•ด์ด๋ฏธ์ง€๋ฅผ ํŒ๋ณ„ํ•ด์•ผํ•˜๋Š”๋ฐ ์ฒ˜์Œ์—๋Š” ์•ผํ•œ์ด๋ฏธ์ง€๋‚˜ ์ž”์ธํ•œ์ด๋ฏธ์ง€๋ฅผ ํŒ๋ณ„ํ•˜๋Š” ๋ชจ๋ธ์„ ๋งŒ๋“ค์—ˆ์—ˆ๋‹ค. ๋งŒ๋“ค๊ณ ๋‚˜์„œ ์–ดํ”Œ ๋‚ด์—์„œ ์ด

beomcoder.tistory.com

 

 

728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€