Home > OS >  Get character out of image with python
Get character out of image with python

Time:04-20

I want to detect the characters in a image like this with python: enter image description here

In this case the code should return the result '6010001'.

How can I get the result out of this image? What do I need?

For your information, if the solution is a AI-solution, there are about 20.000 labeled images.

Thank you in forward :)

CodePudding user response:

You can use opencv-python and pytesseract

import cv2
import pytesseract


img = cv2.imread('img3.jpeg')
text = pytesseract.image_to_string(img)
print(text)

It doesn't work for all images with text, but works for most.

CodePudding user response:

Question: Are all the pictures of similar nature? Meaning the Numbers are stamped into a similar material, or are they random pictures with numbers with different techniques (e.g. pen drawn, stamped etc.)?

If they are all quite similar (nice contrast as in sample pic), I would recommend to write your "own" AI, otherwise use an existing neural network / library (as I assume you may want to avoid the pain of creating your own neural network - and tag a lot of pictures).

If they pics are quite "similar", following suggested approach:

    1. greyscale Image with increase contrast
    1. define box (greater than a digit), scan over image and count 0s, define by trial valid range to detect a digit, avoid overlaps
    1. each hit take area, split it in sectors, e.g. 6x4, count 0s
    1. build a little knowledge base (csv file) of counts per sector for each number from 0-9 (e.g. a string); you will end up in the database with multiple valid strings per each number, just ensure they are unique (otherwise redefine steps 1-3)

In addition I recommend to make yourself a smart knowledge database, meaning: if the digit could not be identified, save digit picture and result. Then make yourself a little review program where it shows you the undefined digits and the result string, you can then manually add them to your knowledge database for the respective number.

Hope it helps. I used the same approach read a lot of different data from screen pictures and store them in a database. Works like a charm. #better do it yourself than using a standard neural network :)

  • Related