Number recognition in images with Python

Introduction

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.

Installation procedure

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.

Execution example

This time, let's recognize the numbers in this image (screen.png). 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.

Installation failure example

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

bonus

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

Number recognition in images with Python
Working with DICOM images in Python
[python, openCV] base64 Face recognition with images
Read text in images with python OCR
Speech recognition in Python
Prime number 2 in Python
Convert PDFs to images in bulk with Python
Bordering images with python Part 1
Base64 encoding images in Python 3
Scraping with selenium in Python
Working with LibreOffice in Python
Scraping with chromedriver in python
Debugging with pdb in Python
Working with sounds in Python
Scraping with Selenium in Python
ABC161D Lunlun Number with python3
Scraping with Tor in Python
Tweet with image in Python
Combined with permutations in Python
Try face recognition with Python
Coursera Machine Learning Challenges in Python: ex3 (Handwritten Number Recognition with Logistic Regression)
Pixel manipulation of images in Python
Testing with random numbers in Python
GOTO in Python with Sublime Text 3
Working with LibreOffice in Python: import
Scraping with Selenium in Python (Basic)
How to collect images in Python
CSS parsing with cssutils in Python
random French number generator with python
Infinite prime number generator in Python3
Numer0n with items made in Python
Open UTF-8 with BOM in Python
Use rospy with virtualenv in Python3
Extract text from images in Python
Post multiple Twitter images with python
[Homology] Count the number of holes in data with Python
Animate multiple still images with Python
Try face recognition with python + OpenCV
Use Python in pyenv with NeoVim
Face recognition with camera with opencv3 + python2.7
Load gif images with Python + OpenCV
Heatmap with Dendrogram in Python + matplotlib
Read files in parallel with Python
Password generation in texto with python
[Python] Collect images easily with icrawler!
Study, number guessing game in Python
Use OpenCV with Python 3 in Window
Until dealing with python in Atom
Handwriting recognition using KNN in Python
Get started with Python in Blender
Object extraction in images by pattern matching using OpenCV with Python
Write documentation in Sphinx with Python Livereload
Get additional data in LDAP with python
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Stress Test with Locust written in Python
English speech recognition with python [speech to text]
Python3> in keyword> True with partial match?
Exclusive control with lock file in Python
Device monitoring with On-box Python in IOS-XE
Amplify images for machine learning with python