Recognize the numbers in the image "easily". This time we will use tesseract from the python library. The code itself is very easy to build, but installing tesseract wasn't surprisingly easy, so make a note of it.
You can complete the installation with the following command from the terminal.
Installation of tesseract
$ brew install tesseract
$ pip install pytesseract
$ pip install pillow
Confirmation of installation completion
$ python
>>> import pytesseract
If there are no errors, you are done.
This time, let's recognize the numbers in this image (screen.png).
Click here for a script for number recognition.
recogition_number.py
# -*- coding: utf-8 -*-
import pytesseract
from PIL import Image
url_img = 'screen.png'
img = Image.open(url_img)
number = pytesseract.image_to_string(img)
print number
Let's run it.
$ python recog_number.py
2048
Oh, he recognized it quickly. This time, there was little noise in the image and it was easy to recognize, but I am satisfied because it was recognized well.
If you install tesseract obediently with pip, you will be addicted to it, so please be careful.
If you have pip, you can install it via pip like any other library.
$ pip install tesseract --user
You will be asked if you think the installation is complete, or if you try to import it, you are not sure.
$ python
>>> import tesseract
Please enter the path to an existing directory where qhull should be installed:
I'm asked to tell me where I have something installed, but I have no idea. Please take care
We are waiting for you to follow us! Qiita: Carat Yoshizaki twitter:@carat_yoshizaki Hatena Blog: Carat COO Blog Home page: Carat
Tutor service "Kikagaku" where you can learn machine learning one-on-one Please feel free to contact us if you are interested in "Kikagaku" where you can learn "Mathematics-> Programming-> Web Applications" at once.
Recommended Posts