Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用模板匹配查找类似的Opencv图像_Python_Image_Opencv_Image Processing_Computer Vision - Fatal编程技术网

Python 使用模板匹配查找类似的Opencv图像

Python 使用模板匹配查找类似的Opencv图像,python,image,opencv,image-processing,computer-vision,Python,Image,Opencv,Image Processing,Computer Vision,我正在尝试使用Opencv中的模板匹配来查找相似的图像。到目前为止,我已经开始工作了,但我现在还不知道如何比较这些图像 我的想法是使用cv2.matchTemplate,然后使用阈值检查是否有任何部分匹配,并删除所有不匹配的部分。 但是,当我看一看产生类似图像的阵列时 (array([0], dtype=int64), array([0], dtype=int64)) (array([], dtype=int64), array([], dtype=int64)) 作为输出 一个不同的形象出

我正在尝试使用Opencv中的模板匹配来查找相似的图像。到目前为止,我已经开始工作了,但我现在还不知道如何比较这些图像

我的想法是使用cv2.matchTemplate,然后使用阈值检查是否有任何部分匹配,并删除所有不匹配的部分。 但是,当我看一看产生类似图像的阵列时

(array([0], dtype=int64), array([0], dtype=int64))
(array([], dtype=int64), array([], dtype=int64))
作为输出

一个不同的形象出现了

(array([0], dtype=int64), array([0], dtype=int64))
(array([], dtype=int64), array([], dtype=int64))
因为我认为输出是完美的,没有匹配,所以空数组将是如何判断它们是不同的还是相同的。但是我使用了与模板相同的图像,这就是输出结果

(array([], dtype=int64), array([], dtype=int64))
我认为这应该与相似的图像相同

我的问题是如何确定哪些相似,哪些不相似? 这是我现在正在使用的代码

def matcher(template, img, match_type, threshold):
    # Match operation
    res = cv2.matchTemplate(img, template, match_type)
    # store coordinates of matched areas
    loc = np.where( res >= threshold)
    return loc

locsame = matcher(template, same, cv2.TM_SQDIFF, 0.8)    
loc1 = matcher(template, sim, cv2.TM_SQDIFF, 0.8)
loc2 = matcher(template, di, cv2.TM_CCOEFF_NORMED, 0.8)
看看和,看看和,还有