how to extract x,y coordinates from OpenCV “cv2.keypoint” object?Declare empty array of specific typeHow to randomly select an item from a list?How to return multiple values from a function?Extracting extension from filename in PythonHow to know if an object has an attribute in PythonHow to make a flat list out of list of listsProper way to declare custom exceptions in modern Python?How to access environment variable values?Cannot find module cv2 when using OpenCVWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How load cv2.KeyPoint and Descriptors correctly on OpenCV 3 with Python 3?

For a benzene shown in a skeletal structure, what does a substituent to the center of the ring mean?

How to 'Let Go' in Meditation?

Upside-Down Pyramid Addition...REVERSED!

Is it cheaper to drop cargo than to land it?

What happens if I start too many background jobs?

Is there a legal ground for stripping the UK of its UN Veto if Scotland and/or N.Ireland split from the UK?

Comment rendre "naysayers" ?

Point of the the Dothraki's attack in GoT S8E3?

Unknowingly ran an infinite loop in terminal

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours

Airbnb - host wants to reduce rooms, can we get refund?

Has any spacecraft ever had the ability to directly communicate with civilian air traffic control?

In Endgame, why were these characters still around?

What is it called when you multiply something eight times?

Number of seconds in 6 weeks

Would "lab meat" be able to feed a much larger global population

Do I really need diodes to receive MIDI?

Why was the battle set up *outside* Winterfell?

Sub query result is 0

Should I replace my bicycle tires if they have not been inflated in multiple years

How do I tell my manager that his code review comment is wrong?

Pressure inside an infinite ocean?

CRT Oscilloscope - part of the plot is missing

Why do money exchangers give different rates to different bills?



how to extract x,y coordinates from OpenCV “cv2.keypoint” object?


Declare empty array of specific typeHow to randomly select an item from a list?How to return multiple values from a function?Extracting extension from filename in PythonHow to know if an object has an attribute in PythonHow to make a flat list out of list of listsProper way to declare custom exceptions in modern Python?How to access environment variable values?Cannot find module cv2 when using OpenCVWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?How load cv2.KeyPoint and Descriptors correctly on OpenCV 3 with Python 3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








6















I tried to use the following code:



 xCoordinate=point.x


(point is type of cv2.keyPoint)
It gives me error saying cv2.keyPoint has no attribute 'x'










share|improve this question




























    6















    I tried to use the following code:



     xCoordinate=point.x


    (point is type of cv2.keyPoint)
    It gives me error saying cv2.keyPoint has no attribute 'x'










    share|improve this question
























      6












      6








      6


      3






      I tried to use the following code:



       xCoordinate=point.x


      (point is type of cv2.keyPoint)
      It gives me error saying cv2.keyPoint has no attribute 'x'










      share|improve this question














      I tried to use the following code:



       xCoordinate=point.x


      (point is type of cv2.keyPoint)
      It gives me error saying cv2.keyPoint has no attribute 'x'







      python opencv numpy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 9 '16 at 6:21









      mengmengxyzmengmengxyz

      1692510




      1692510






















          6 Answers
          6






          active

          oldest

          votes


















          8














          You can use:



          import numpy as np

          pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)


          pts will be an array of keypoints.






          share|improve this answer
































            11














            point.pt is a tuple(x,y)`.



            So,



            x = point.pt[0]
            y = point.pt[1]


            or,



            (x,y) = point.pt





            share|improve this answer
































              4














              Read the docs.



              class KeyPoint



              Data structure for salient point detectors.



              • Point2f pt
                -- coordinates of the keypoint


              • float size
                -- diameter of the meaningful keypoint neighborhood


              • float angle ...¶


              So point.pt is a Point2f.



              Try x,y= point.pt






              share|improve this answer




















              • 2





                point.pt.x is invalid, please correct it as: x, y = point.pt

                – Nirmal
                Oct 26 '18 at 5:30


















              1














              Here is my take (runable code):



              import cv2, os
              import numpy as np
              import matplotlib.pyplot as plt

              # INITIALISATION
              filename = os.path.join('foo', 'bar.jpg')
              img0 = cv2.imread(filename) # original image
              gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
              sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
              f, (ax1, ax2) = plt.subplots(1, 2) # create subplots

              # DETECT AND DRAW KEYPOINTS
              # sift.detect() returns a list of keypoints
              # keypoint is a standard class of opencv (not just SIFT-related)
              kp = sift.detect(gray,None) # calculates SIFT points
              img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
              ax1.imshow(img1) # plot

              # RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
              # Reade these and make numpy array
              pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
              cols = pts[:,0]
              rows = pts[:,1]
              ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
              ax2.scatter(cols, rows)

              plt.show()





              share|improve this answer
































                1














                OpenCV provides a function for this. You can run:



                pts = cv2.KeyPoint_convert(kp)





                share|improve this answer






























                  0














                  I solved your problem like this.



                  kp,des = surf.detectAndCompute(img,None) 
                  pts = [p.pt for p in kp]


                  Now you get a list of x,y co-ordinates for all keypoints in your image.






                  share|improve this answer

























                    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',
                    autoActivateHeartbeat: false,
                    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%2f35884409%2fhow-to-extract-x-y-coordinates-from-opencv-cv2-keypoint-object%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown

























                    6 Answers
                    6






                    active

                    oldest

                    votes








                    6 Answers
                    6






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    8














                    You can use:



                    import numpy as np

                    pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)


                    pts will be an array of keypoints.






                    share|improve this answer





























                      8














                      You can use:



                      import numpy as np

                      pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)


                      pts will be an array of keypoints.






                      share|improve this answer



























                        8












                        8








                        8







                        You can use:



                        import numpy as np

                        pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)


                        pts will be an array of keypoints.






                        share|improve this answer















                        You can use:



                        import numpy as np

                        pts = np.float([kp[idx].pt for idx in range(0, len(kp))]).reshape(-1, 1, 2)


                        pts will be an array of keypoints.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Mar 22 at 20:59









                        user664303

                        1,51221027




                        1,51221027










                        answered Mar 9 '16 at 8:40









                        Francesco NazzaroFrancesco Nazzaro

                        1,839717




                        1,839717























                            11














                            point.pt is a tuple(x,y)`.



                            So,



                            x = point.pt[0]
                            y = point.pt[1]


                            or,



                            (x,y) = point.pt





                            share|improve this answer





























                              11














                              point.pt is a tuple(x,y)`.



                              So,



                              x = point.pt[0]
                              y = point.pt[1]


                              or,



                              (x,y) = point.pt





                              share|improve this answer



























                                11












                                11








                                11







                                point.pt is a tuple(x,y)`.



                                So,



                                x = point.pt[0]
                                y = point.pt[1]


                                or,



                                (x,y) = point.pt





                                share|improve this answer















                                point.pt is a tuple(x,y)`.



                                So,



                                x = point.pt[0]
                                y = point.pt[1]


                                or,



                                (x,y) = point.pt






                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Dec 22 '18 at 4:45









                                skumhest

                                54




                                54










                                answered May 6 '17 at 8:13









                                saikat sarkarsaikat sarkar

                                11115




                                11115





















                                    4














                                    Read the docs.



                                    class KeyPoint



                                    Data structure for salient point detectors.



                                    • Point2f pt
                                      -- coordinates of the keypoint


                                    • float size
                                      -- diameter of the meaningful keypoint neighborhood


                                    • float angle ...¶


                                    So point.pt is a Point2f.



                                    Try x,y= point.pt






                                    share|improve this answer




















                                    • 2





                                      point.pt.x is invalid, please correct it as: x, y = point.pt

                                      – Nirmal
                                      Oct 26 '18 at 5:30















                                    4














                                    Read the docs.



                                    class KeyPoint



                                    Data structure for salient point detectors.



                                    • Point2f pt
                                      -- coordinates of the keypoint


                                    • float size
                                      -- diameter of the meaningful keypoint neighborhood


                                    • float angle ...¶


                                    So point.pt is a Point2f.



                                    Try x,y= point.pt






                                    share|improve this answer




















                                    • 2





                                      point.pt.x is invalid, please correct it as: x, y = point.pt

                                      – Nirmal
                                      Oct 26 '18 at 5:30













                                    4












                                    4








                                    4







                                    Read the docs.



                                    class KeyPoint



                                    Data structure for salient point detectors.



                                    • Point2f pt
                                      -- coordinates of the keypoint


                                    • float size
                                      -- diameter of the meaningful keypoint neighborhood


                                    • float angle ...¶


                                    So point.pt is a Point2f.



                                    Try x,y= point.pt






                                    share|improve this answer















                                    Read the docs.



                                    class KeyPoint



                                    Data structure for salient point detectors.



                                    • Point2f pt
                                      -- coordinates of the keypoint


                                    • float size
                                      -- diameter of the meaningful keypoint neighborhood


                                    • float angle ...¶


                                    So point.pt is a Point2f.



                                    Try x,y= point.pt







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Nov 20 '18 at 2:05

























                                    answered Mar 9 '16 at 6:37









                                    roadrunner66roadrunner66

                                    3,92331834




                                    3,92331834







                                    • 2





                                      point.pt.x is invalid, please correct it as: x, y = point.pt

                                      – Nirmal
                                      Oct 26 '18 at 5:30












                                    • 2





                                      point.pt.x is invalid, please correct it as: x, y = point.pt

                                      – Nirmal
                                      Oct 26 '18 at 5:30







                                    2




                                    2





                                    point.pt.x is invalid, please correct it as: x, y = point.pt

                                    – Nirmal
                                    Oct 26 '18 at 5:30





                                    point.pt.x is invalid, please correct it as: x, y = point.pt

                                    – Nirmal
                                    Oct 26 '18 at 5:30











                                    1














                                    Here is my take (runable code):



                                    import cv2, os
                                    import numpy as np
                                    import matplotlib.pyplot as plt

                                    # INITIALISATION
                                    filename = os.path.join('foo', 'bar.jpg')
                                    img0 = cv2.imread(filename) # original image
                                    gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
                                    sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
                                    f, (ax1, ax2) = plt.subplots(1, 2) # create subplots

                                    # DETECT AND DRAW KEYPOINTS
                                    # sift.detect() returns a list of keypoints
                                    # keypoint is a standard class of opencv (not just SIFT-related)
                                    kp = sift.detect(gray,None) # calculates SIFT points
                                    img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
                                    ax1.imshow(img1) # plot

                                    # RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
                                    # Reade these and make numpy array
                                    pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
                                    cols = pts[:,0]
                                    rows = pts[:,1]
                                    ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
                                    ax2.scatter(cols, rows)

                                    plt.show()





                                    share|improve this answer





























                                      1














                                      Here is my take (runable code):



                                      import cv2, os
                                      import numpy as np
                                      import matplotlib.pyplot as plt

                                      # INITIALISATION
                                      filename = os.path.join('foo', 'bar.jpg')
                                      img0 = cv2.imread(filename) # original image
                                      gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
                                      sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
                                      f, (ax1, ax2) = plt.subplots(1, 2) # create subplots

                                      # DETECT AND DRAW KEYPOINTS
                                      # sift.detect() returns a list of keypoints
                                      # keypoint is a standard class of opencv (not just SIFT-related)
                                      kp = sift.detect(gray,None) # calculates SIFT points
                                      img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
                                      ax1.imshow(img1) # plot

                                      # RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
                                      # Reade these and make numpy array
                                      pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
                                      cols = pts[:,0]
                                      rows = pts[:,1]
                                      ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
                                      ax2.scatter(cols, rows)

                                      plt.show()





                                      share|improve this answer



























                                        1












                                        1








                                        1







                                        Here is my take (runable code):



                                        import cv2, os
                                        import numpy as np
                                        import matplotlib.pyplot as plt

                                        # INITIALISATION
                                        filename = os.path.join('foo', 'bar.jpg')
                                        img0 = cv2.imread(filename) # original image
                                        gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
                                        sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
                                        f, (ax1, ax2) = plt.subplots(1, 2) # create subplots

                                        # DETECT AND DRAW KEYPOINTS
                                        # sift.detect() returns a list of keypoints
                                        # keypoint is a standard class of opencv (not just SIFT-related)
                                        kp = sift.detect(gray,None) # calculates SIFT points
                                        img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
                                        ax1.imshow(img1) # plot

                                        # RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
                                        # Reade these and make numpy array
                                        pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
                                        cols = pts[:,0]
                                        rows = pts[:,1]
                                        ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
                                        ax2.scatter(cols, rows)

                                        plt.show()





                                        share|improve this answer















                                        Here is my take (runable code):



                                        import cv2, os
                                        import numpy as np
                                        import matplotlib.pyplot as plt

                                        # INITIALISATION
                                        filename = os.path.join('foo', 'bar.jpg')
                                        img0 = cv2.imread(filename) # original image
                                        gray = cv2.cvtColor(img0, cv2.COLOR_BGR2GRAY) # convert to grayscale
                                        sift = cv2.xfeatures2d.SIFT_create() # initialize SIFT
                                        f, (ax1, ax2) = plt.subplots(1, 2) # create subplots

                                        # DETECT AND DRAW KEYPOINTS
                                        # sift.detect() returns a list of keypoints
                                        # keypoint is a standard class of opencv (not just SIFT-related)
                                        kp = sift.detect(gray,None) # calculates SIFT points
                                        img1=cv2.drawKeypoints(gray,kp, None) # mae new image with keypoints drawn
                                        ax1.imshow(img1) # plot

                                        # RETREIVE KEYPOINTS COORDINATES AND DRAW MANUALLY
                                        # Reade these and make numpy array
                                        pts = np.asarray([[p.pt[0], p.pt[1]] for p in kp])
                                        cols = pts[:,0]
                                        rows = pts[:,1]
                                        ax2.imshow(cv2.cvtColor(img0, cv2.COLOR_BGR2RGB))
                                        ax2.scatter(cols, rows)

                                        plt.show()






                                        share|improve this answer














                                        share|improve this answer



                                        share|improve this answer








                                        edited Nov 2 '18 at 12:58

























                                        answered Nov 2 '18 at 10:40









                                        quickbugquickbug

                                        1,72441117




                                        1,72441117





















                                            1














                                            OpenCV provides a function for this. You can run:



                                            pts = cv2.KeyPoint_convert(kp)





                                            share|improve this answer



























                                              1














                                              OpenCV provides a function for this. You can run:



                                              pts = cv2.KeyPoint_convert(kp)





                                              share|improve this answer

























                                                1












                                                1








                                                1







                                                OpenCV provides a function for this. You can run:



                                                pts = cv2.KeyPoint_convert(kp)





                                                share|improve this answer













                                                OpenCV provides a function for this. You can run:



                                                pts = cv2.KeyPoint_convert(kp)






                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Mar 28 at 13:29









                                                VikVik

                                                304210




                                                304210





















                                                    0














                                                    I solved your problem like this.



                                                    kp,des = surf.detectAndCompute(img,None) 
                                                    pts = [p.pt for p in kp]


                                                    Now you get a list of x,y co-ordinates for all keypoints in your image.






                                                    share|improve this answer





























                                                      0














                                                      I solved your problem like this.



                                                      kp,des = surf.detectAndCompute(img,None) 
                                                      pts = [p.pt for p in kp]


                                                      Now you get a list of x,y co-ordinates for all keypoints in your image.






                                                      share|improve this answer



























                                                        0












                                                        0








                                                        0







                                                        I solved your problem like this.



                                                        kp,des = surf.detectAndCompute(img,None) 
                                                        pts = [p.pt for p in kp]


                                                        Now you get a list of x,y co-ordinates for all keypoints in your image.






                                                        share|improve this answer















                                                        I solved your problem like this.



                                                        kp,des = surf.detectAndCompute(img,None) 
                                                        pts = [p.pt for p in kp]


                                                        Now you get a list of x,y co-ordinates for all keypoints in your image.







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        edited Oct 6 '17 at 9:06









                                                        Shaido

                                                        13.4k123045




                                                        13.4k123045










                                                        answered Oct 6 '17 at 8:49









                                                        Alexander HuntAlexander Hunt

                                                        1




                                                        1



























                                                            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.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function ()
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35884409%2fhow-to-extract-x-y-coordinates-from-opencv-cv2-keypoint-object%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

                                                            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                                                            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                                            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현