If you look at the documentation, it should be SIFT_create().

sift = cv2.SIFT_create()
print(sift)
kp = sift.detect(img1_gray, None)

But, why are you reading images with plt.imread?

The reason I’m asking, you are converting to the gray-scale using BGR2GRAY. But plt.imread returns image as RGB format. Therefore, if you are going to use plt.imread:

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


def rgb2gray(rgb):
    return np.dot(rgb[..., :3], [0.2989, 0.5870, 0.1140]).astype(np.uint8)


if __name__ == '__main__':
    img1 = plt.imread('../data/input/frame000013.png')
    img2 = plt.imread('../data/input/frame000014.png')
    img1_gray = rgb2gray(img1)
    sift = cv2.SIFT_create()
    print(sift)
    kp = sift.detect(img1_gray, None)
    print(kp)

or if you choose cv2.imread:

import cv2
import matplotlib.pyplot as plt

if __name__ == '__main__':
    img1 = cv2.imread('../data/input/frame000013.png')
    img2 = cv2.imread('../data/input/frame000014.png')
    img1_gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
    sift = cv2.SIFT_create()
    print(sift)
    kp = sift.detect(img1_gray, None)
    print(kp)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top