Search code examples
pythonopencvfeature-extractionsiftsurf

Python opencv 3 SIFT feature extraction


I want to change the following two commands which are written in opencv 2.3 .

fea_det=cv2.FeatureDetector_create("SIFT")
des_ext=cv2.DescriptorExtractor_create("SIFT")

In opencv 3, I know that there is a command which create SIFT, so

fea_det=cv2.xfeatures2d.SIFT_create()

But what should I use for des_ext ? I am asking that what is the equivalent code of "cv2.DescriptorExtractor_create("SIFT")" in opencv 3?


Solution

  • FeatureDetector_create and DescriptorExtractor_create since OpenCV 3 were moved to xfeatures2d subdirectory.

    >>> sift = cv2.xfeatures2d.SIFT_create()
    >>> (kps, descs) = sift.detectAndCompute(gray, None)
    >>> print("# kps: {}, descriptors: {}".format(len(kps), descs.shape))
    # kps: 274, descriptors: (274, 128)
    

    Take a look for more information at this article.