r/learnpython • • Nov 14 '17

Reading text from images with Python

Hi, So, I want to build a small project for personal use, that will read text from books covers and write it in to the table like Excel or Sql. For example, I am showing a book cover to camera and written app detect the title of the book, year, author etc. Like detect text on the cover and categorize them, i guess. I already done some researches about that for a couple hours, but I`am still confused what tools do I need and from where I should begin. So, I would appreciate any suggestion or advices about this.

At the moment the list of tools is next: Numpy, MatplotLib,Py-tesseract?, OpenCv(not sure if needed)...

For the record, my software development skills is a little poor, but I am not afraid of teaching new stuff if situation required and learning while building something is more productive for me. So, yeah, thanks in advance for wasting time on me :3

Update: Okay, thank for all responses I got. Just want to clarify one more thing. Do I need to use machine learning to categorize detected data(For example, tell the difference between title and the name of the author at the book cover) or would be enough to have Cv libraries?

9 Upvotes

9 comments sorted by

View all comments

1

u/Yoghurt42 Nov 14 '17

OpenCV could be useful for character detection (what part of images are letters), while (py)tesseract would do the character recognition.

OpenCV is not strictly needed, but might be useful for preprocessing. Tesseract is a good OCR, but if you give it a raw color image, the detection rate would be poor. Tesseract works best with 1-bit (grayscale also works, but not as well in my experience) images that are cleaned up from clutter.

My advice would be first to manually preprocess an image you have, and fiddle with it until tesseract can detect the text. Then do it again with another image; once you know which adjustments you have to make, you can either use pillow, if those adjustments are only things like converting into 1-bit image with a given threshold, or OpenCV if you need to do more work (like extracting the part with the text first)

1

u/Michanix Nov 14 '17

So, before start throwing data/images to Tesseract, I should get rid of or bluring any background colors and probably images at the background, if they are any. So, cv would only be able detect characters and then pass them through ocr to read these characters. Perhaps, even resize them, so it would be easier for cv to work with given data.

2

u/Yoghurt42 Nov 14 '17

So, before start throwing data/images to Tesseract, I should get rid of or bluring any background colors and probably images at the background, if they are any.

No. You should convert it into an image where each pixel is either completely black or completely white. Tesseract can handle some noise, but sometimes it's necessary to manually remove some more.

The wiki has some tips

2

u/Michanix Nov 14 '17

Oh, okay, thank you.

2

u/Versuno Nov 15 '17

Checkout this tutorial on thresholding with opencv. It will give you an idea of some of the processing you can do to the image with opencv, before trying to recognize character with an OCR like Tesseract.

1

u/Michanix Nov 15 '17

Thank you, this might help me.