Methods of feature matching Python Opencv
up vote
0
down vote
favorite
I want to determine value of cards on on a bigger picture, having a template pic, for example.
My code below with ORB_create way.
img1 = cv2.imread('templates/j.png',0)
img2 = cv2.imread('templates/large j.png',0)
orb = cv2.ORB_create(edgeThreshold=8, patchSize=31, nlevels=8,
fastThreshold=20, scaleFactor=1.4,
WTA_K=2,scoreType=cv2.ORB_HARRIS_SCORE,
firstLevel=0, nfeatures=5000)
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches= sorted(matches, key=lambda x:x.distance)
print(len(matches))
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
cv2.imshow('s',img3)
cv2.waitKey(0)
Here are output.
At first case edgeThreshold=8 , at second edgeThreshold=12. As you can see, flags aren't correct! They compare white areas on the pictures, instead of 'J'. If I try to compare '9' or '7' with 'J' - result is wrong too. (there should not be matches, but they are). Maybe problem is in params? I changed 'edgeThreshold', 'scaleFactor' and 'nfeatures' - no sense.
That is even a good example of pictures, they may be angled or with broken prospect.
Also, I've tried AKAZE_create - there is no matches at all, zero.
detector = cv2.AKAZE_create()
(kps1, descs1) = detector.detectAndCompute(im1, None)
(kps2, descs2) = detector.detectAndCompute(im2, None)
#print("keypoints: , descriptors: ".format(len(kps1), descs1.shape))
#print("keypoints: , descriptors: ".format(len(kps2), descs2.shape))
bf = cv2.BFMatcher(cv2.NORM_MINMAX)
matches = bf.knnMatch(descs1,descs2, k=2) # typo fixed
print(len(matches))
python opencv
add a comment |
up vote
0
down vote
favorite
I want to determine value of cards on on a bigger picture, having a template pic, for example.
My code below with ORB_create way.
img1 = cv2.imread('templates/j.png',0)
img2 = cv2.imread('templates/large j.png',0)
orb = cv2.ORB_create(edgeThreshold=8, patchSize=31, nlevels=8,
fastThreshold=20, scaleFactor=1.4,
WTA_K=2,scoreType=cv2.ORB_HARRIS_SCORE,
firstLevel=0, nfeatures=5000)
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches= sorted(matches, key=lambda x:x.distance)
print(len(matches))
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
cv2.imshow('s',img3)
cv2.waitKey(0)
Here are output.
At first case edgeThreshold=8 , at second edgeThreshold=12. As you can see, flags aren't correct! They compare white areas on the pictures, instead of 'J'. If I try to compare '9' or '7' with 'J' - result is wrong too. (there should not be matches, but they are). Maybe problem is in params? I changed 'edgeThreshold', 'scaleFactor' and 'nfeatures' - no sense.
That is even a good example of pictures, they may be angled or with broken prospect.
Also, I've tried AKAZE_create - there is no matches at all, zero.
detector = cv2.AKAZE_create()
(kps1, descs1) = detector.detectAndCompute(im1, None)
(kps2, descs2) = detector.detectAndCompute(im2, None)
#print("keypoints: , descriptors: ".format(len(kps1), descs1.shape))
#print("keypoints: , descriptors: ".format(len(kps2), descs2.shape))
bf = cv2.BFMatcher(cv2.NORM_MINMAX)
matches = bf.knnMatch(descs1,descs2, k=2) # typo fixed
print(len(matches))
python opencv
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to determine value of cards on on a bigger picture, having a template pic, for example.
My code below with ORB_create way.
img1 = cv2.imread('templates/j.png',0)
img2 = cv2.imread('templates/large j.png',0)
orb = cv2.ORB_create(edgeThreshold=8, patchSize=31, nlevels=8,
fastThreshold=20, scaleFactor=1.4,
WTA_K=2,scoreType=cv2.ORB_HARRIS_SCORE,
firstLevel=0, nfeatures=5000)
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches= sorted(matches, key=lambda x:x.distance)
print(len(matches))
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
cv2.imshow('s',img3)
cv2.waitKey(0)
Here are output.
At first case edgeThreshold=8 , at second edgeThreshold=12. As you can see, flags aren't correct! They compare white areas on the pictures, instead of 'J'. If I try to compare '9' or '7' with 'J' - result is wrong too. (there should not be matches, but they are). Maybe problem is in params? I changed 'edgeThreshold', 'scaleFactor' and 'nfeatures' - no sense.
That is even a good example of pictures, they may be angled or with broken prospect.
Also, I've tried AKAZE_create - there is no matches at all, zero.
detector = cv2.AKAZE_create()
(kps1, descs1) = detector.detectAndCompute(im1, None)
(kps2, descs2) = detector.detectAndCompute(im2, None)
#print("keypoints: , descriptors: ".format(len(kps1), descs1.shape))
#print("keypoints: , descriptors: ".format(len(kps2), descs2.shape))
bf = cv2.BFMatcher(cv2.NORM_MINMAX)
matches = bf.knnMatch(descs1,descs2, k=2) # typo fixed
print(len(matches))
python opencv
I want to determine value of cards on on a bigger picture, having a template pic, for example.
My code below with ORB_create way.
img1 = cv2.imread('templates/j.png',0)
img2 = cv2.imread('templates/large j.png',0)
orb = cv2.ORB_create(edgeThreshold=8, patchSize=31, nlevels=8,
fastThreshold=20, scaleFactor=1.4,
WTA_K=2,scoreType=cv2.ORB_HARRIS_SCORE,
firstLevel=0, nfeatures=5000)
kp1, des1 = orb.detectAndCompute(img1,None)
kp2, des2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = bf.match(des1,des2)
matches= sorted(matches, key=lambda x:x.distance)
print(len(matches))
img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:10],None, flags=2)
cv2.imshow('s',img3)
cv2.waitKey(0)
Here are output.
At first case edgeThreshold=8 , at second edgeThreshold=12. As you can see, flags aren't correct! They compare white areas on the pictures, instead of 'J'. If I try to compare '9' or '7' with 'J' - result is wrong too. (there should not be matches, but they are). Maybe problem is in params? I changed 'edgeThreshold', 'scaleFactor' and 'nfeatures' - no sense.
That is even a good example of pictures, they may be angled or with broken prospect.
Also, I've tried AKAZE_create - there is no matches at all, zero.
detector = cv2.AKAZE_create()
(kps1, descs1) = detector.detectAndCompute(im1, None)
(kps2, descs2) = detector.detectAndCompute(im2, None)
#print("keypoints: , descriptors: ".format(len(kps1), descs1.shape))
#print("keypoints: , descriptors: ".format(len(kps2), descs2.shape))
bf = cv2.BFMatcher(cv2.NORM_MINMAX)
matches = bf.knnMatch(descs1,descs2, k=2) # typo fixed
print(len(matches))
python opencv
python opencv
asked Nov 10 at 14:11
Кирилл
114
114
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239794%2fmethods-of-feature-matching-python-opencv%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown