2
$\begingroup$

I'm trying to extract some particular information from the image(png).

I tried to extract the text using the below code

import cv2
import pytesseract
import os
from PIL import Image
import sys

def get_string(img_path):
    # Read image with opencv
    img = cv2.imread(img_path)

    # Convert to gray
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    # Apply dilation and erosion to remove some noise
    kernel = np.ones((1, 1), np.uint8)
    img = cv2.dilate(img, kernel, iterations=1)
    img = cv2.erode(img, kernel, iterations=1)

    # Write the image after apply opencv to do some ...
    cv2.imwrite("thres.png", img)
    # Recognize text with tesseract for python
    result = pytesseract.image_to_string(Image.open("invoice.png"))
    os.remove("invoice.png")

    return result

if __name__ == '__main__':
    from sys import argv

    if len(argv)<2:
        print("Usage: python image-to-text.py relative-filepath")
    else:
        print('--- Start recognize text from image ---')
        for i in range(1,len(argv)):
            print(argv[i])
            print(get_string(argv[i]))
            print()
            print()

        print('------ Done -------')

But I want to extract data from particular fields.

Such as

 a) INVOICE NO.
 b) CUSTOMER NO.
 c) SUBTOTAL
 d) TOTAL
 e) DATE

How can I extract the required information from the below image "invoice"?

PFB

enter image description here

$\endgroup$
  • $\begingroup$ Optical character recognition for invoice parsing is a heavily researched subject within Artificial Intelligence. Perhaps you can add some additional information in which direction the project will go. For example, should the system works with semantic tagging, with neural networks, with training data and so on? $\endgroup$ – Manuel Rodriguez Nov 5 '19 at 7:47
  • $\begingroup$ @ManuelRodriguez The system With Neural Networks, without any training data $\endgroup$ – Krishna Nov 5 '19 at 8:46
  • 1
    $\begingroup$ Found something here(dida.do/blog/extracting-information-from-documents). Trying to extract data with Python OCR tool pytesseract, Levenshtein distance, NLP. $\endgroup$ – Krishna Nov 5 '19 at 10:51
1
$\begingroup$

Optical character recognition can't be done by a single algorithm but a longer workflow is needed which contains of steps. The task “document segmentation” separates large regions in a document into smaller chunks. The amount of literature about layout analysis and document segmentation is low.

In recent works, neural networks are trained on larger datasets for invoice recognition.[1] This is done with the help of Convolutional Neural Networks from the YOLOv2 framework. Low level input features are converted into high level concepts. This allows to parse region of information in the document.

[1] Forczmański, Paweł, et al. "Segmentation of Scanned Documents Using Deep-Learning Approach." International Conference on Computer Recognition Systems. Springer, Cham, 2019.

$\endgroup$
  • $\begingroup$ Any references you would like to suggest to experiment in extracting the info from image files. $\endgroup$ – Krishna Nov 7 '19 at 9:07
  • $\begingroup$ @Krishna Did i understand the concern right, that the amount of references to existing academic papers and websites in the internet is too low? The problem is, that a single source is indeed a bit small but the probability is high, that within a timespan of two years new papers are published about the subject. $\endgroup$ – Manuel Rodriguez Nov 7 '19 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.