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.
enter image description hereenter image description here



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.



enter image description hereenter image description here



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))









share|improve this question

























    up vote
    0
    down vote

    favorite












    I want to determine value of cards on on a bigger picture, having a template pic, for example.
    enter image description hereenter image description here



    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.



    enter image description hereenter image description here



    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))









    share|improve this question























      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.
      enter image description hereenter image description here



      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.



      enter image description hereenter image description here



      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))









      share|improve this question













      I want to determine value of cards on on a bigger picture, having a template pic, for example.
      enter image description hereenter image description here



      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.



      enter image description hereenter image description here



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 10 at 14:11









      Кирилл

      114




      114



























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Syphilis

          Darth Vader #20