当前位置: 首页 > news >正文

python opencv的sift特征检测(Scale-Invariant Feature Transform)

sift

官方文档地址:https://docs.opencv.org/4.10.0/da/df5/tutorial_py_sift_intro.html

  • 创建SIFT实例cv2.SIFT.create()
  • 特征检测sift.detect
  • 描述子sift.compute/sift.detectAndCompute
  • 画特征cv2.drawKeypoints

原图

在这里插入图片描述

特征点

在这里插入图片描述

代码

import cv2first = './12.png'
'''
sift 特征检测
官方文档地址:https://docs.opencv.org/4.10.0/da/df5/tutorial_py_sift_intro.html
'''
if __name__ == "__main__":# 读取图片,转成灰度图img = cv2.imread(first)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# 创建SIFT实例sift = cv2.SIFT.create()# 特征检测# sift.detect() function finds the keypoint in the images. You can pass a mask if you want to search only a part of image.# Each keypoint is a special structure which has many attributes like its (x,y) coordinates,# size of the meaningful neighbourhood, angle which specifies its orientation,# response that specifies strength of keypoints etc.kp = sift.detect(gray, None)print(f"关键点:{kp}")print(f"f关键点:{type(kp)}")print(f"f关键点:{len(kp)}")print(f"f关键点:{kp[0]}")# 画出关键点# DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS可以展示特征点的大小和方向img = cv2.drawKeypoints(gray, kp, img, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)cv2.imshow("sift", img)cv2.waitKey(0)cv2.destroyAllWindows()# kp, des = sift.compute(gray, kp) 用计算出来的特征点计算描述子# 或者直接计算特征点和描述子# Here kp will be a list of keypoints and des is a numpy array of shape: len(kp) X 128kp, des = sift.detectAndCompute(gray, None)# print(kp)# print(type(kp))# print(kp[0])print(des.shape)print(des[0])
关键点:(< cv2.KeyPoint 0x11f179110>, < cv2.KeyPoint 0x11f179140>, < cv2.KeyPoint 0x11f179470>, < cv2.KeyPoint 0x11f179560>, < cv2.KeyPoint 0x11f179530>, < cv2.KeyPoint 0x11f179500>, < cv2.KeyPoint 0x11f1794d0>, < cv2.KeyPoint 0x11f1794a0>, < cv2.KeyPoint 0x11f17a9d0>, < cv2.KeyPoint 0x11f228c60>, < cv2.KeyPoint 0x11f228c30>, < cv2.KeyPoint 0x11f2288a0>, < cv2.KeyPoint 0x11f228930>, < cv2.KeyPoint 0x11f2289c0>, < cv2.KeyPoint 0x11f2289f0>, < cv2.KeyPoint 0x11f228ab0>, < cv2.KeyPoint 0x11f22bed0>, < cv2.KeyPoint 0x11f244570>, < cv2.KeyPoint 0x11f2443c0>, < cv2.KeyPoint 0x11f2443f0>, < cv2.KeyPoint 0x11f244510>, < cv2.KeyPoint 0x11f2445a0>, < cv2.KeyPoint 0x11f244630>, < cv2.KeyPoint 0x11f244660>, < cv2.KeyPoint 0x11f244690>, < cv2.KeyPoint 0x11f2446c0>, < cv2.KeyPoint 0x11f2446f0>, < cv2.KeyPoint 0x11f244720>)
f关键点:<class 'tuple'>
f关键点:28
f关键点:< cv2.KeyPoint 0x11f179110>
(28, 128)
[  0.   0.   0.   0.   0.   0.   0.   2.   1.   0.   0.   0.   0.   3.25.  18.   0.   0.   0.   0.   0.  18.  23.   2.   0.   0.   0.   0.0.   2.   1.   1.  23.   0.   0.   0.   0.   0.   0.  10. 139.   2.0.   0.   6.  29.  81. 136.  13.   0.   0.   0. 106. 162.  82.  26.23.   0.   0.   0.  22.  16.   7.  36.  41.   4.   0.   0.   0.   0.0.   1. 162.  34.   0.   0.  26.  11.   5.  22.  71.   6.   0.   0.162.  83.   5.   7. 122.   7.   0.   0.  70.  11.   1.  17.  22.   3.0.   0.   0.   0.   0.   0. 162.  37.   0.   0.  15.   2.   0.   0.83.  10.   0.   0. 162.  36.   0.   0.  94.  11.   0.   0.  78.   9.0.   0.]
http://www.lryc.cn/news/511620.html

相关文章:

  • 若依定时任务
  • k8s-node2 NotReady 节点NotReady如何解决?
  • Ubuntu通过mDNS实现局域网local域名和octoprint域名访问
  • 短视频矩阵账号管理技术源码搭建详解,支持OEM
  • 【源码 导入教程 文档 讲解】基于springboot校园新闻管理系统源码和论文
  • Spark SQL DML语句
  • 开发微信小程序的过程与心得
  • 【1224】数据结构(sizeof/数组的长度定义/读取字符串函数/线性表长度/左值右值/静态变量/指针与引用)
  • Android笔记(四十一):TabLayout内的tab不滚动问题
  • 基于pytorch的深度学习基础3——模型创建与nn.Module
  • Debian-linux运维-docker安装和配置
  • Docker完整技术汇总
  • 在JavaScript文件中定义方法和数据(不是在对象里定以数据和方法,不要搞错了)
  • python爬虫爬抖音小店商品数据+数据可视化
  • 关于 覆铜与导线之间间距较小需要增加间距 的解决方法
  • uniapp中Nvue白屏问题 ReferenceError: require is not defined
  • 在 Windows 上,如果忘记了 MySQL 密码 重置密码
  • 《PyTorch:从基础概念到实战应用》
  • 前端:改变鼠标点击物体的颜色
  • Java-33 深入浅出 Spring - FactoryBean 和 BeanFactory BeanPostProcessor
  • HTML4笔记
  • python报错ModuleNotFoundError: No module named ‘visdom‘
  • linux-21 目录管理(一)mkdir命令,创建空目录
  • 总结-常见缓存替换算法
  • 【Vue】如何在 Vue 3 中使用组合式 API 与 Vuex 进行状态管理的详细教程
  • VSCode 插件开发实战(十五):如何支持多语言
  • 面试241228
  • ​Python数据序列化模块pickle使用
  • Spring Boot对访问密钥加解密——HMAC-SHA256
  • HTML 元素:网页构建的基础