python - 如何在图像中找到签名?

标签 python opencv image-processing pattern-matching opencv-contour

目前,我正在一个需要从医生处方中提取签名的项目。我被困在一个地方,我在opencv中使用轮廓来查找处方中的图案,但我不知道如何比较轮廓以匹配签名图案。

这是签名模式:
Image of signature I want to find in the prescription

这是裁剪的处方:
Image of the cropped prescription

在裁剪的处方中使用轮廓后,我发现了以下模式:
Image of contours in cropped prescription

最佳答案

#import necessary packages
import cv2
import numpy as np
import matplotlib.pyplot as plt
#read the query and the template image in gray_sacle
ref_img = cv2.imread("ref_img.jpg",0)
template_img = cv2.imread("temp_img.jpg",0)
w, h = template_img.shape[::-1]
#the methods to be used for template matching
methods = ['cv2.TM_CCOEFF_NORMED','cv2.TM_CCORR_NORMED']
#set a threshold to qualify for a match
threshold = 0.9
#loop overboth the methods and do template matching
#plot the results if the threshold is qualified
for meth in methods:
    img = ref_img.copy()

    method = eval(meth)

    # Apply template Matching
    res = cv2.matchTemplate(img,template_img,method)
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)

    top_left = max_loc
    bottom_right = (top_left[0] + w, top_left[1] + h)

    if max_val >= threshold:
        print(min_val,max_val)
        cv2.rectangle(img,top_left, bottom_right, 0, 2)

        plt.subplot(121),plt.imshow(res,cmap = 'gray')
        plt.title('Matching Result'), plt.xticks([]), plt.yticks([])
        plt.subplot(122),plt.imshow(img,cmap = 'gray')
        plt.title('Detected Point'), plt.xticks([]), plt.yticks([])
        plt.suptitle(meth)

        plt.show()

Output for cv2.TM_CCOEFF_NORMED

Output for cv2.TM_CCORR_NORMED

关于python - 如何在图像中找到签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59249274/

相关文章:

python-2.7 - 使用 ORB 检查重复图像

python - 在 OpenCV python 中使用 seamlessClone 生成具有 "ghost"个对象的图像

image-processing - 在 opencv 中集成 cvblobslib

python测量两个相似图像的质量

python - 处理视频时如何使用 matplotlib 随时间绘制每秒帧数 (fps)?

python - 使用 Python 找出当前是否处于夏令时的时区

python - 在 Flask SqlAlchemy 中定义同一字段的主键和外键

python - 实现DFT,反函数无法正常工作

python - 在 Django 中填充 URLFields 的合法值的确切模式是什么?

java - 图像处理库