gpt4 book ai didi

python-3.x - 如何区分 python 中的护照和 PAN 卡扫描图像

转载 作者:太空宇宙 更新时间:2023-11-03 23:08:44 25 4
gpt4 key购买 nike

目标是使用 Opencv 识别输入的扫描图像是护照还是 PAN 卡。

我使用 skimage 的 structural_similarity(compare_ssim) 方法将输入扫描图像与护照和 PAN 卡模板图像进行比较。

但在这两种情况下我的得分都很低。

这是我试过的代码

from skimage.measure import compare_ssim as ssim
import matplotlib.pyplot as plt
import numpy as np
import cv2enter code here

img1 = cv2.imread('PAN_Template.jpg', 0)
img2 = cv2.imread('PAN_Sample1.jpg', 0)

def prepare_img(im):
size = 300, 200
im = cv2.resize(im, size)
return im

img1 = prepare_img(img1)
img2 = prepare_img(img2)

def compare_images(imageA, imageB):
s = ssim(imageA, imageB)
return s

ssim = compare_images(img1, img2)

print(ssim)

将 PAN 卡模板与护照进行比较,我的 ssim 分数为 0.12将 PAN 卡模板与 PAN 卡进行比较,得分为 0.20

由于两者的分数非常接近,我无法通过代码区分它们。

如果有人有任何其他解决方案或方法,请提供帮助。

这是一个示例图片 PAN Scanned Image

最佳答案

您还可以通过这两张图片的均方误差 (MSE) 来比较两张图片。

def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])

# return the MSE, the lower the error, the more "similar"
# the two images are
return err

关于python-3.x - 如何区分 python 中的护照和 PAN 卡扫描图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54093601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com