When learning sift for image stitching program, I found that there is a piece of knowledge that I don't understand in the code written by others.
# 建立SIFT生成器
descriptor = cv2.SIFT_create()
# 检测SIFT特征点,并计算描述子
(kps, features) = descriptor.detectAndCompute(image, None)
kps = np.float32([kp.pt for kp in kps])
Note: Generally, the function cv2.xfeatures2d.SIFT_create() is used to create a sift generator. The opencv version used here is 4.5.5. It is recommended to use cv2.SIFT_create() when the opencv version is 4.0 or higher. Because sift is copyrighted, cv2.xfeatures2d.SIFT_create() can be used directly in opencv version 3.4.2.16. When the opencv version is too high, cv2.xfeatures2d.SIFT_create() will appear as follows
In this case, it is recommended to roll back the opencv version or use cv2.SIFT_create()
At first I didn’t understand what kp.pt meant, but I found out after inquiry
kps, features = cv2.SIFT_create().detectAndCompute()
In the return value of the above function, kps is the key point, and the information it contains includes:
pt: coordinates of key points
angle: Angle, indicating the direction of the key point.
size: the size of the diameter of the point
octave: The data extracted from which layer of the pyramid.
response: The degree of response, to be precise, the degree of the corner point.
class_id: When classifying pictures, you can use class_id to distinguish each feature point. If it is not set, it is -1, and you need to set it yourself.