How to do template matching without opencv?

How to do template matching without OpenCV?

I have an order invoice of documents belonging to Amazon, eBay, Flipkart, SnapDeal, and I want to extract less information from the order invoice. Since the fields like the order number, customer name, order details will be present at different positions in these 4 templates,

I need to first classify to which of these 4 templates the input image will belong to and after identifying the template I can do my next work of text extraction using tesseract and regex buy writing code for specific templates.

When I searched I found the only OpenCV had this feature I was not able to find any convolution neural network model . Are there any such neural network models available for template matching and classification?

I cannot use the standard model available for classifying dogs and cats because here I'm dealing with the image of an invoice templates which has only text with rows and columns in some format.

Topic similar-documents cnn classification

Category Data Science


import numpy as np
import matplotlib.image as img
import matplotlib.pyplot as plt
from skimage.metrics import structural_similarity as ssim

def rgb2gray(rgb):
    return np.dot(rgb[...,:3], [0.299, 0.587, 0.144])

full_image = rgb2gray(img.imread("img/full_image.png"))
sub_image = rgb2gray(img.imread("img/sub_image.png"))

full_w,full_h = full_image.shape[:2]
sub_w,sub_h = sub_image.shape[:2]

print(full_w,full_h)
print(sub_w,sub_h)

winW = 0
found = False
while winW < full_w - sub_w and found == False:
    winH = 0
    while winH < full_h - sub_h:
        window = full_image[winW:winW+sub_w, winH:winH+sub_h]
        if ssim(sub_image, window) > 0.80:
            found = True
            print("found", ssim(sub_image, window))
            plt.imshow(window)
            break
        winH += 2
    winW += 2

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.