如何使用python比较来自不同图像的对象

问题描述

我正在努力满足我的其中一项要求。 我想比较两个图像。在这两个图像中,主要对象是关键。我需要检查这些键是否相同。 这是持续的要求,每次我都会得到不同的钥匙图像与原始图像进行比较。图像和对象(键)大小不同。 我需要分析每个图像中键的脊和凹口,并基于此我需要给出不同图像中键是否相同或如何相同的结果。 我尝试使用 Homography、OpenCV 和 Canny 检查边缘和相似点以进行比较,但每次我得到不同的结果,因为在比较图像时会考虑图像背景。

注意:我想比较两个不同图像中存在的对象相似性,而不是图像比较。

我正在考虑的一种方法是,我将用 Canny 比较两个图像的边缘,然后开始用 Homography 检查相似点,但我被困在如何将下面的代码用于两个或多个图像?

import cv2
import numpy as np

image = cv2.imread('MyKey11.jpg')
original = image.copy()
gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray,(3,3),0)
canny = cv2.Canny(blurred,120,255,1)
kernel = np.ones((5,5),np.uint8)
dilate = cv2.dilate(canny,kernel,iterations=1)

# Find contours
cnts = cv2.findContours(dilate,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]

# Iterate thorugh contours and filter for ROI
image_number = 0
for c in cnts:
    x,y,w,h = cv2.boundingRect(c)
    cv2.rectangle(image,(x,y),(x + w,y + h),(36,12),2)
    ROI = original[y:y+h,x:x+w]
    cv2.imwrite("ROI_{}.png".format(image_number),ROI)
    image_number += 1

cv2.imshow('canny',canny)
cv2.imshow('image',image)
cv2.waitKey(0)

请提出解决方案。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...