def test_find_scene():
scenes = {}
for s in os.listdir('txxscene'):
if '-' in s: continue
i = cv2.imread(os.path.join('txxscene', s), cv2.IMREAD_GRAYSCALE)
scenes[s] = i
# names = [os.path.join('scene', c) for c in os.listdir('scene')]
imgs = {}
for n in os.listdir('scene'):
i = cv2.imread(os.path.join('scene', n), cv2.IMREAD_GRAYSCALE)
i = cv2.resize(i, (960, 540))
imgs[n] = i
for name, img in imgs.iteritems():
for scene, tmpl in scenes.iteritems():
res = cv2.matchTemplate(img, tmpl, cv2.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)
if max_val < 0.6:
continue
x, y = max_loc
h, w = tmpl.shape
cv2.rectangle(img, (x, y), (x+w, y+h), 255, 2)
print name, scene, max_val, min_val
cv2.imshow('found', img)
cv2.waitKey()
评论列表
文章目录