$ brew install tesseract
$ pip3 install pyocr
$ curl -L -o /usr/local/share/tessdata/jpn.traineddata 'https://github.com/tesseract-ocr/tessdata/raw/master/jpn.traineddata'
$ tesseract --list-langs
List of available languages (4):
eng
jpn
osd
snum
from PIL import Image
import sys
import pyocr
import pyocr.builders
tools = pyocr.get_available_tools()
if len(tools) == 0:
print("No OCR tool found")
sys.exit(1)
# The tools are returned in the recommended order of usage
tool = tools[0]
txt = tool.image_to_string(
Image.open('{path}'),
lang="jpn",
builder=pyocr.builders.TextBuilder(tesseract_layout=6)
)
print(txt)
Recommended Posts