【发布时间】:2018-08-10 08:05:22
【问题描述】:
我正在使用模板匹配来检测大图像中的小图像。 检测到后,我会抓取检测到的图像主图的中心点(x y)。
谁能建议我如何获取特定中心点的阴影/颜色?
我知道模板匹配忽略了颜色,基于这个例子,有没有办法获取特定像素的颜色强度?那个中心点
# Python program to illustrate
# template matching
import cv2
import numpy as np
import time
import sys
# Read the main image
img_rgb = cv2.imread('test.png')
# Convert it to grayscale
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
# Read the template
template = cv2.imread('template.png',0)
# Store width and heigth of template in w and h
w, h = template.shape[::-1]
# Perform match operations.
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
# Specify a threshold
threshold = 0.90
# Store the coordinates of matched area in a numpy array
loc = np.where( res >= threshold)
xyMiddle = ""
for pt in zip(*loc[::-1]):
xyMiddle = str(pt[0] + w/2) +"," +str(pt[1] + h/5)
if(xyMiddle != ""):
print(xyMiddle)
【问题讨论】:
标签: python opencv cv2 template-matching