imn1
2019-12-06 00:20:43 +08:00
OK,我的错,copy 代码没留意灰度预处理的部分(我代码图像预处理是写在一个类里面,忘了)
修正 #3
应该是这个,简单测试了几幅图
------------------------------------------
#!/usr/bin/env python3
# -*-coding:utf-8 -*-
import numpy
from cv2 import cv2
image = r'c:\temp\1.jpg'
# target = r'c:\temp\2.jpg'
# target = r'c:\temp\1142d03a4b21edd545812af46e7f84cc.jpg'
target = r'c:\temp\Download-HD-Bamboo-Wallpapers.jpg'
# target = r'c:\temp\Free-HD-Bamboo-Wallpapers-Download.jpg'
img_gray = cv2.imread(target, cv2.IMREAD_GRAYSCALE)
tImg = cv2.imread(image, cv2.IMREAD_GRAYSCALE)
h, w = tImg.shape[:2]
h0 = h//4
h1 = h-h//4
w0 = w//4
w1 = w-w//4
template = tImg[h0:h1, w0:w1]
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.9
loc = numpy.where( res >= threshold)
print(loc)
if len(loc[0]): print("True")
else: print("False")
------------------------------------------------
注释同上