python opencv-3.0 SIFT/SURF 特征提取与匹配
2017-12-27 20:20
2086 查看
一、环境准备
目前 Opencv 有2.x 和 3.x 版本,两个版本之间的差异主要是一些功能函数被放置到了不同的功能模块,因此大多数情况两个版本的代码并不能通用。建议安装 Anaconda,自行下载相应版本。直接命令安装Opencv3, lake :conda install -c menpo opencv3 pip install lake
二、SIFT/SURF 特征提取与匹配
# coding: utf-8 from matplotlib import pyplot as plt from lake.decorator import time_cost import cv2 print 'cv version: ', cv2.__version__ def bgr_rgb(img): (r, g, b) = cv2.split(img) return cv2.merge([b, g, r]) def orb_detect(image_a, image_b): # feature match orb = cv2.ORB_create() kp1, des1 = orb.detectAndCompute(image_a, None) kp2, des2 = orb.detectAndCompute(image_b, None) # create BFMatcher object bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) # Match descriptors. matches = bf.match(des1, des2) # Sort them in the order of their distance. matches = sorted(matches, key=lambda x: x.distance) # Draw first 10 matches. img3 = cv2.drawMatches(image_a, kp1, image_b, kp2, matches[:100], None, flags=2) return bgr_rgb(img3) @time_cost def sift_detect(img1, img2, detector='surf'): if detector.startswith('si'): print "sift detector......" sift = cv2.xfeatures2d.SURF_create() else: print "surf detector......" sift = cv2.xfeatures2d.SURF_create() # find the keypoints and descriptors with SIFT kp1, des1 = sift.detectAndCompute(img1, None) kp2, des2 = sift.detectAndCompute(img2, None) # BFMatcher with default params bf = cv2.BFMatcher() matches = bf.knnMatch(des1, des2, k=2) # Apply ratio test good = [[m] for m, n in matches if m.distance < 0.5 * n.distance] # cv2.drawMatchesKnn expects list of lists as matches. img3 = cv2.drawMatchesKnn(img1, kp1, img2, kp2, good, None, flags=2) return bgr_rgb(img3) if __name__ == "__main__": # load image image_a = cv2.imread('./img1.jpg') image_b = cv2.imread('./img2.png') # ORB # img = orb_detect(image_a, image_b) # SIFT or SURF img = sift_detect(image_a, image_b) plt.imshow(img) plt.show()
三、输出展示
cv version: 3.1.0 surf detector...... ==> time-cost: 0.187422 sift_detect
Output:
img1
img2
相关文章推荐
- opencv-python 提取sift特征并匹配
- OpenCV中feature2D学习——FAST特征点检测与SIFT/SURF/BRIEF特征提取与匹配
- OpenCV中feature2D学习——SIFT和SURF算子实现特征点提取与匹配
- OpenCV中feature2D学习——SIFT和SURF算子实现特征点提取与匹配
- Python-OpenCV:sift(),SURF() 特征提取
- 使用RANSAC提纯SIFT和SURF特征点,达到鲁棒匹配的效果(OpenCV 2.4.13下,源码)
- opencv 特征点提取算法 SIFT SURF ORB FAST LBP学习(二)
- Opencv中sift特征提取与匹配代码
- opencv图像特征检测及匹配(harris,sift,surf,fast,breif,orb,BFmatch,FlannBasedMatcher)
- Opencv下利用SIFT、SURF、ORB三种特征点实现图像匹配
- OpenCV Using Python——基于SURF特征提取和金字塔LK光流法的单目视觉三维重建
- OpenCV2学习笔记(十二):特征提取算法SIFT与SURF
- Opencv下利用SIFT、SURF、ORB三种特征点实现图像匹配
- 使用Opencv2.4.9进行SIFT特征点提取和匹配
- OpenCV-Python 特征点检测 (含SIFT/SURF/ORB/KAZE/FAST/BRISK/AKAZE)
- SIFT图像特征提取 python3.4 + opencv3.1.0代码
- opencv之SURF特征点提取及匹配
- 使用openCV提取sift;surf;hog特征
- OpenCV实践之路——Qt中用opencv提取和匹配SIFT特征点
- OpenCV中提取SIFT特征点、图像匹配、图像配准