首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在图片中找到签名?

如何在图片中找到签名?
EN

Stack Overflow用户
提问于 2019-12-09 20:49:57
回答 1查看 466关注 0票数 0

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

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2019-12-09 23:33:42

代码语言:javascript
复制
#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()

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59249274

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档