python图像匹配_opencvpython中的图像匹配

我一直在做一个项目,用opencvpython识别相机中显示的标志。

我已经尝试过使用surf、颜色直方图匹配和模板匹配。但在这3个问题中,它并不总是返回正确的答案。我现在想要的是,解决我这个问题的最好办法是什么。

模板图像示例:

以下是摄像头中显示的标志示例。

如果这是我想要识别的图像,该怎么用?在

更新matchTemplate中的代码flags=["Cambodia.jpg","Laos.jpg","Malaysia.jpg","Myanmar.jpg","Philippines.jpg","Singapore.jpg","Thailand.jpg","Vietnam.jpg","Indonesia.jpg","Brunei.jpg"]

while True:

methods = 'cv2.TM_CCOEFF_NORMED'

list_of_pics=[]

for flag in flags:

template= cv2.imread(flag,0)

img = cv2.imread('philippines2.jpg',0)

# generate Gaussian pyramid for A

G = template.copy()

gpA = [G]

for i in xrange(6):

G = cv2.pyrDown(G)

gpA.append(G)

n=0

for x in gpA:

w, h = x.shape[::-1]

method = eval(methods)#

# Apply template Match

res = cv2.matchTemplate(img,x,method)

matchVal=res[0][0]

picDict={"matchVal":matchVal,"name":flag}

list_of_pics.append(picDict)

n=n+1

newlist = sorted(list_of_pics, key=operator.itemgetter('matchVal'),reverse=True)

#print newlist

matched_image=newlist[0]['name']

print matched_image

k=cv2.waitKey(10)

if (k==27):

break

cv2.destroyAllWindows()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值