栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

OpenCV-Python Feature2D 特征点检测(含ORB/KAZE/FAST/BRISK/AKAZE)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

OpenCV-Python Feature2D 特征点检测(含ORB/KAZE/FAST/BRISK/AKAZE)

代码在git
link

Open3.x-Python 特征点检测方法
  • 对于OpenCV3.x-Python,特征点检测及显示方法如下:

  • 下面就重点介绍OpenCV3.x-Python中的各种特征点检测方法的使用示例。

  • 测试图像为标准的lena.png

    AKAZE Feature Detection

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


BRISK Feature Detection

import cv2
import numpy
 
def main():
	img = cv2.imread("lena.png")
	cv2.imshow('Input Image', img)
	cv2.waitKey(0)
 
 
	brisk = cv2.BRISK_create()
	keypoints = brisk.detect(img, None)
	
	# 必须要先初始化img2
	img2 = img.copy()
	img2 = cv2.drawKeypoints(img, keypoints, img2, color=(0,255,0))
	cv2.imwrite('bk.png', img2)
	cv2.imshow('Detected BRISK keypoints', img2)
	cv2.waitKey(0)
    
if __name__ == '__main__':
	main()


Fast Feature Detection

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 24 14:08:30 2021

@author: ledi
"""

#!/usr/bin/env python
# -*- coding=utf-8 -*-
# Summary: 使用OpenCV3.x-Python检测FAST特征点
# Author:  Amusi
# Date:    2018-03-17
# Reference: https://docs.opencv.org/master/df/d74/classcv_1_1FastFeatureDetector.html
 
import cv2
import numpy
 
def main():
 
	img = cv2.imread("lena.png")
	cv2.imshow('Input Image', img)
	cv2.waitKey(0)
 
	# 2018-03-17 Amusi: OpenCV3.x FeatureDetector写法有变化
	# OpenCV2.x
	# fast = cv2.FastFeatureDetector()
	# keypoints = fast.detect(img, None)
	
	# OpenCV3.x
	# 注意有_create()后缀
	fast = cv2.FastFeatureDetector_create()
	keypoints = fast.detect(img, None)
	
	# 必须要先初始化img2
	img2 = img.copy()
	img2 = cv2.drawKeypoints(img, keypoints, img2, color=(0,255,0))
	cv2.imwrite('bk.png', img2)
	cv2.imshow('Detected FAST keypoints', img2)
	cv2.waitKey(0)
    
if __name__ == '__main__':
	main()

KAZE Feature Detection

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 24 14:15:45 2021

@author: ledi
"""

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


ORB Feature Detection

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/590183.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号