Python中的手写签名相似度匹配

问题描述 投票:0回答:1

我正在尝试解决我有两个数字手写签名的问题,我必须找到它们之间的相似度百分比

下面是代码

import cv2
from skimage.metrics import structural_similarity as ssim
import numpy as np
# TODO add contour detection for enhanced accuracy

def removeWhiteSpace(img):
    # img = cv2.imread('ws.png') # Read in the image and convert to grayscale
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = 255*(gray < 128).astype(np.uint8) # To invert the text to white
    coords = cv2.findNonZero(gray) # Find all non-zero points (text)
    x, y, w, h = cv2.boundingRect(coords) # Find minimum spanning bounding box
    rect = img[y:y+h, x:x+w]
    return rect
    
def match(path1, path2):
    # read the images
    img1 = cv2.imread(path1)
    img2 = cv2.imread(path2)
    img1 = removeWhiteSpace(img1)
    img2 = removeWhiteSpace(img2)
    # turn images to grayscale
    img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
    # resize images for comparison
    img1 = cv2.resize(img1, (300, 300))
    img2 = cv2.resize(img2, (300, 300))
    # display both images
    cv2.imshow("One", img1)
    cv2.imshow("Two", img2)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    similarity_value = "{:.2f}".format(ssim(img1, img2,gaussian_weights = True,sigma= 1.2,use_sample_covariance = False)*100)
    # print("answer is ", float(similarity_value),
    #       "type=", type(similarity_value))
    return float(similarity_value)



path1 = 'sample_images\img3.jpeg'
path2 = 'sample_images\img4.jpeg'
similarity_value = match(path1,path2)
print(similarity_value)

示例#1

下面是两张图

图片1:enter image description here 图片2:enter image description here

当执行上面的代码时,我得到77.93相似度,这是一个很好的百分比

示例#2

下面是两张图

图片1:enter image description here 图片2:enter image description here

执行上述代码时,我得到66.36相似度匹配

询问

由于两个图像看起来相似,我如何提高 example#2 中的相似性匹配百分比?

python python-3.x opencv scikit-image handwriting-recognition
1个回答
0
投票

可以给我数据集吗

© www.soinside.com 2019 - 2024. All rights reserved.