我想匹配来自我的a.jpg和b.jpg的照片。
但是有一些我不想匹配的领域。
我应该如何掩饰它?
(PS:如果将这些区域转移到黑色,则会影响cv2.matchTemplate
)
import cv2
import numpy as np
img1 = cv2.imread("a.jpg")
img2 = cv2.imread("b.jpg")
myROI = img2[183:374,293:408]
# here I want to mask a part of myROI ..
# It means that I don't want to match something in my picture...
# How should I do ?
res = cv2.matchTemplate(img1,myROI,method= eval('cv2.TM_CCOEFF_NORMED'))
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
print max_val*100 # score
B.JPG
答案 0 :(得分:0)
# -*- coding: utf-8 -*-
import cv2
import numpy as np
img1 = cv2.imread("a.jpg")
img2 = cv2.imread("b.jpg")
mymask = cv2.imread("mask.jpg") # mask shape must = template
# mask only run in method = CV_TM_SQDIFF and CV_TM_CCORR_NORMED.
me= eval('cv2.TM_CCORR_NORMED')
res1 = cv2.matchTemplate(img1,img2,method= me, mask = mymask)
res2 = cv2.matchTemplate(img1,img2,method= eval('cv2.TM_CCORR_NORMED'))
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res1)
print max_val*100 # score 1 -> 62
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res2)
print max_val*100 # score 2 -> 99
https://i.stack.imgur.com/TsqA9.jpg