Ask Your Question
0

how to solve this opencv-program

asked 2019-05-30 09:46:04 -0600

seon-a gravatar image

updated 2019-05-31 07:58:51 -0600

supra56 gravatar image

http://jwlee2218.blogspot.com/2017/11...

i want to make a program that searches the wally.

this is a code:

import bumpy as np

import cv2

import matplotlib.pyplot as pat





img1=cv2.imread(‘icy.jpg’,0)

img2=cv2.imread(‘wally.png’,0)

sift=cv2.xfeatures2d.SIFT_create()

kp1,des1=sift.detectAndCompute(img1,None)

kp1,des2=sift.detectAndCompute(img2,None)

bf=cv2.BFMatcher()

matches=bf.knnMatch(des1,des2,k=2)

good=[]




for m,n in matches:
    if m.distance<0.75*n.distance:
        good.append([m])





img3=cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,None,flags=2)

plt.imshow(img3)


plt.show()

But i have another errors.

this is a error: syntaxerror keyword can't be an expression

I don't understand what they say

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2019-05-31 08:00:10 -0600

supra56 gravatar image

You got typo error. Change this:

import bumpy as np

to:

import numpy as np
edit flag offensive delete link more

Comments

i did. but this error continues...

seon-a gravatar imageseon-a ( 2019-05-31 09:15:31 -0600 )edit

Does this help:

ret_list = []
good = []
for m, n in matches:
    if m.distance < 0.75 * n.distance:
        good.append([m])

good.sort(key=lambda x: x[0].distance)


# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(sub_image, kp1, main_image, kp2, good, flags=2, outImg=None,
                                      matchColor=(255, 255, 0))
plt.imshow(img3), plt.show()

ret_list = []
for match in good:
    index = match[0].trainIdx
    point = kp2[index].pt
    ret_list.append((int(point[0]), int(point[1])))
supra56 gravatar imagesupra56 ( 2019-05-31 10:41:59 -0600 )edit

I didn't test it. I merely spotted two waldos so far.

supra56 gravatar imagesupra56 ( 2019-06-01 08:11:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-05-30 09:44:56 -0600

Seen: 135 times

Last updated: May 31 '19