欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

OpenCV-Python Feature2D 特征点检测 (SIFT,SURF)

发布时间:2025/4/5 python 28 豆豆
生活随笔 收集整理的这篇文章主要介绍了 OpenCV-Python Feature2D 特征点检测 (SIFT,SURF) 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

git
LINK
下面介绍属于nonfree的特征检测方法,如SIFT和SURF。

这些方法在opencv-contrib中,所以想要使用前,请卸载当前非contrib版本的opencv,即pip uninstall opencv-python后;再重新安装opencv-contrib-python,即pip install opencv-contrib-python

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-contrib-python

SIFT Feature Detection

#!/usr/bin/env python # -*- coding=utf-8 -*- # Summary: 使用OpenCV3.x-Python检测SIFT特征点 # Author: Amusi # Date: 2018-03-17 # Reference: https://docs.opencv.org/master/d5/d3c/classcv_1_1xfeatures2d_1_1SIFT.htmlimport cv2 import numpydef main():img = cv2.imread("lena.png")cv2.imshow('Input Image', img)cv2.waitKey(0)# 检测sift = cv2.xfeatures2d.SIFT_create()keypoints = sift.detect(img, None)# 显示# 必须要先初始化img2img2 = img.copy()img2 = cv2.drawKeypoints(img, keypoints, img2, color=(0,255,0))cv2.imwrite('sift.png', img2)cv2.imshow('Detected SIFT keypoints', img2)cv2.waitKey(0)if __name__ == '__main__':main()


SURF Feature Detection

#!/usr/bin/env python # -*- coding=utf-8 -*- # Summary: 使用OpenCV3.x-Python检测SURF特征点 # Author: Amusi # Date: 2018-03-17 # Reference: https://docs.opencv.org/master/d5/df7/classcv_1_1xfeatures2d_1_1SURF.htmlimport cv2 import numpydef main():img = cv2.imread("lena.png")cv2.imshow('Input Image', img)cv2.waitKey(0)# 检测surf = cv2.xfeatures2d.SURF_create()keypoints = surf.detect(img, None)# 显示# 必须要先初始化img2img2 = img.copy()img2 = cv2.drawKeypoints(img, keypoints, img2, color=(0,255,0))cv2.imshow('Detected SURF keypoints', img2)cv2.waitKey(0)if __name__ == '__main__':main()

总结

以上是生活随笔为你收集整理的OpenCV-Python Feature2D 特征点检测 (SIFT,SURF)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。