From 14af3696400987a6c103dd0879037c56fc66d26e Mon Sep 17 00:00:00 2001 From: abidrahmank Date: Fri, 30 Aug 2013 11:11:06 +0530 Subject: [PATCH] Python bindings for KeyPoint methods Usage: import numpy as np import cv2 img = cv2.imread('messi5.jpg',0) sift = cv2.SIFT() kp = sift.detect(img) pts = cv2.KeyPoint_convert(kp) kps = cv2.KeyPoint_convert(pts.reshape(-1,1,2)) overlap = cv2.KeyPoint_overlap(kp[0],kp[1]) --- modules/core/doc/basic_structures.rst | 42 +++++++++++++++++++++ modules/core/include/opencv2/core/types.hpp | 6 +-- modules/highgui/doc/user_interface.rst | 2 +- 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/modules/core/doc/basic_structures.rst b/modules/core/doc/basic_structures.rst index 353d404f7d..f768a54f64 100644 --- a/modules/core/doc/basic_structures.rst +++ b/modules/core/doc/basic_structures.rst @@ -638,6 +638,48 @@ The keypoint constructors :param _class_id: object id +KeyPoint::convert +-------------------- + +This method converts vector of keypoints to vector of points or the reverse, where each keypoint is assigned the same size and the same orientation. + +.. ocv:function:: KeyPoint::convert(const std::vector& keypoints, CV_OUT std::vector& points2f, const std::vector& keypointIndexes=std::vector()) + +.. ocv:function:: KeyPoint::convert(const std::vector& points2f, CV_OUT std::vector& keypoints, float size=1, float response=1, int octave=0, int class_id=-1) + +.. ocv:pyfunction:: cv2.KeyPoint_convert(keypoints[, keypointIndexes]) -> points2f + +.. ocv:pyfunction:: cv2.KeyPoint_convert(points2f[, size[, response[, octave[, class_id]]]]) -> keypoints + + :param keypoints: Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB + + :param points2f: Array of (x,y) coordinates of each keypoint + + :param keypointIndexes: Array of indexes of keypoints to be converted to points. (Acts like a mask to convert only specified keypoints) + + :param _size: keypoint diameter + + :param _response: keypoint detector response on the keypoint (that is, strength of the keypoint) + + :param _octave: pyramid octave in which the keypoint has been detected + + :param _class_id: object id + + +KeyPoint::overlap +-------------------- + +This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint regions' intersection and area of keypoint regions' union (considering keypoint region as circle). If they don't overlap, we get zero. If they coincide at same location with same size, we get 1. + +.. ocv:function:: KeyPoint::overlap(const KeyPoint& kp1, const KeyPoint& kp2) + +.. ocv:pyfunction:: cv2.KeyPoint_overlap(kp1, kp2) -> retval + + :param kp1: First keypoint + + :param kp2: Second keypoint + + DMatch ------ .. ocv:class:: DMatch diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 3ca86add05..fd2f834e2a 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -551,18 +551,18 @@ public: size_t hash() const; //! converts vector of keypoints to vector of points - static void convert(const std::vector& keypoints, + CV_WRAP static void convert(const std::vector& keypoints, CV_OUT std::vector& points2f, const std::vector& keypointIndexes=std::vector()); //! converts vector of points to the vector of keypoints, where each keypoint is assigned the same size and the same orientation - static void convert(const std::vector& points2f, + CV_WRAP static void convert(const std::vector& points2f, CV_OUT std::vector& keypoints, float size=1, float response=1, int octave=0, int class_id=-1); //! computes overlap for pair of keypoints; //! overlap is a ratio between area of keypoint regions intersection and //! area of keypoint regions union (now keypoint region is circle) - static float overlap(const KeyPoint& kp1, const KeyPoint& kp2); + CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2); CV_PROP_RW Point2f pt; //!< coordinates of the keypoints CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood diff --git a/modules/highgui/doc/user_interface.rst b/modules/highgui/doc/user_interface.rst index 0ffd69ac5e..d4055ef6f0 100644 --- a/modules/highgui/doc/user_interface.rst +++ b/modules/highgui/doc/user_interface.rst @@ -81,7 +81,7 @@ The function ``imshow`` displays an image in the specified window. If the window If window was created with OpenGL support, ``imshow`` also support :ocv:class:`ogl::Buffer` , :ocv:class:`ogl::Texture2D` and :ocv:class:`gpu::GpuMat` as input. -.. note:: This function should be followed by ``waitKey`` function which displays the image for specified milliseconds. Otherwise, it won't display the image. +.. note:: This function should be followed by ``waitKey`` function which displays the image for specified milliseconds. Otherwise, it won't display the image. For example, ``waitKey(0)`` will display the window infinitely until any keypress (it is suitable for image display). ``waitKey(25)`` will display a frame for 25 ms, after which display will be automatically closed. (If you put it in a loop to read videos, it will display the video frame-by-frame) namedWindow