SIFT feature extraction and matching

1. The principle part of sift feature:

Detailed explanation of SIFT features - Brook_icv - Blog Park (cnblogs.com)

 sift feature extraction algorithm_July_Zh1's blog-CSDN blog_sift feature extraction algorithm

Two, sift feature extraction practice part:

Code implementation: Python+OpenCV

import cv2
def sift_kp(image):
    gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    sift = cv2.SIFT.create()
    kp,des = sift.detectAndCompute(image, None)
    #kp_image = cv2.drawKeypoints(image, kp, None)
    kp_image = cv2.drawKeypoints(image, kp, image, (122, 255, 122), flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    return kp_image,kp,des
#image = cv2.imread('E:\pythonProject\\N2.jpg')
#image = cv2.imread('E:\pythonProject\image1.jpg')
image = cv2.imread('E:\pythonProject\ldh1.jpg')
kp_image, _, des = sift_kp(image)
print(image.shape, des.shape)
cv2.namedWindow('sift features',cv2.WINDOW_NORMAL)
cv2.imshow('sift features', kp_image)
if cv2.waitKey(0) == 27:
    cv2.destroyAllWindows()

For the old version of OpenCV, the fourth line uses

sift = cv2.xfeatures2d_SIFT.create()

replace 

Reference: OpenCV-Python - Image SIFT Feature Extraction - Short Book (jianshu.com)

3. The key point display part of the sift feature:

cv2.drawKeypoints(image, keypoints, outImage, color=None, flags=None)
image original image, can be three-channel or single-channel image;

keypoints feature point vector, each element in the vector is a KeyPoint object, which contains various attribute information of the feature point;
outImage the canvas image drawn by the feature point, which can be the original image;
color information of the drawn feature point, drawn by default It is a random color;
flags The drawing mode of the feature point is actually the information that sets the feature point that needs to be drawn, and those that do not need to be drawn. There are the following modes to choose from:

DRAW_MATCHES_FLAGS_DEFAULT: Only draw the coordinate points of the feature points, which are displayed as small dots on the image, and the coordinates of the center of each small dot are the coordinates of the feature points.
DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG: The function does not create an output image, but draws directly in the output image variable space. It is required that the output image variable itself is initialized, and both size and type are already initialized variables.
DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS : Single-point feature points are not drawn.
DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS: When drawing feature points, circles with directions are drawn. This method displays the coordinates, size and direction of the image at the same time, which is the most characteristic drawing method.

Reference: cv2.drawKeypoints function (opencv learning)_Diligent Sao Nian Blog-CSDN Blog_cv2.drawkeypoints

Guess you like

Origin blog.csdn.net/GGY1102/article/details/128430788