代码在gitlink
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()