pip install opencv-contrib-python
pip install opencv-python
import cv2
# 读取图像
img_path = 'img.jpg'
img = cv2.imread(img_path)
# 计算图像的高斯金字塔
gaussian_pyramid = [img]
for i in range(4):
img = cv2.pyrDown(img)
gaussian_pyramid.append(img)
for i in range(5):
sift = cv2.xfeatures2d.SIFT_create(nOctaveLayers=1)
# 计算图像的SIFT特征
keypoints, descriptors = sift.detectAndCompute(gaussian_pyramid[i], None)
# 绘制特征金字塔图
img_with_keypoints = cv2.drawKeypoints(gaussian_pyramid[i], keypoints, None)
cv2.imshow(f'Gaussian Pyramid Level {i}', img_with_keypoints)
cv2.waitKey(0)
留言