发布于2020-03-21 17:31 阅读(3269) 评论(0) 点赞(9) 收藏(0)
特征点检测算法
Harris角点检测
cv2.cornerHarris(gray,blockSize=4,ksize=5,k=0.04)
- import cv2
- import matplotlib.pyplot as plt
- import numpy as np
-
- def cv_show(name,image):
- """图像显示函数
- name:字符串,窗口名称
- img:numpy.ndarray,图像
- """
- cv2.namedWindow(name,cv2.WINDOW_NORMAL)
- cv2.imshow(name,image)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-
- if __name__=="__main__":
- img = cv2.imread('.\data\Box.jpg')
- gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
- gray = np.float32(gray)
- # 角点检测
- dst = cv2.cornerHarris(gray,blockSize=4,ksize=5,k=0.04)
- # 对角点进行膨胀操作
- dst = cv2.dilate(dst,None)
- img[dst>0.01*dst.max()] = [0,0,255]
- # 显示图像
- cv_show('Harris Corners',img)
SIFT特征检测
- import cv2
- import numpy as np
-
- def cv_show(name,image):
- """图像显示函数
- name:字符串,窗口名称
- img:numpy.ndarray,图像
- """
- cv2.namedWindow(name,cv2.WINDOW_NORMAL)
- cv2.imshow(name,image)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
-
- if __name__=="__main__":
- img = cv2.imread('.\data\975-1.jpg')
- gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
-
- sift = cv2.xfeatures2d.SIFT_create()
- keypoints,descriptor = sift.detectAndCompute(gray,None)
- # 在图上绘制关键点
- img = cv2.drawKeypoints(image=img,outImage=img,keypoints=keypoints,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS,color=(255,255,0))
- cv_show('sift_keypoints',img)
- cv2.imwrite('.\opencv_python\SIFT.jpg',img)
SURF特征检测
- import cv2
- import numpy as np
-
- def cv_show(name,image):
- """图像显示函数
- name:字符串,窗口名称
- img:numpy.ndarray,图像
- """
- cv2.namedWindow(name,cv2.WINDOW_NORMAL)
- cv2.imshow(name,image)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
- if __name__=="__main__":
- img = cv2.imread('.\data\975-1.jpg')
- gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
-
- surf = cv2.xfeatures2d.SURF_create(8000)
- keypoints,descriptor = surf.detectAndCompute(gray,None)
-
- img = cv2.drawKeypoints(image=img,outImage=img,keypoints=keypoints,flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS,color=(255,255,0))
- cv_show('surf_keypoints',img)
- cv2.imwrite('.\opencv_python\SURF.jpg',img)
ORB特征检测
- def img_show(name,image):
- """matplotlib图像显示函数
- name:字符串,图像标题
- img:numpy.ndarray,图像
- """
- if len(image.shape) == 3:
- image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
- plt.imshow(image,'gray')
- plt.xticks([])
- plt.yticks([])
- plt.xlabel(name,fontproperties='FangSong',fontsize=12)
-
- if __name__=="__main__":
- img1 = cv2.imread('.\data\974-1.jpg')
- img2 = cv2.imread('.\data\975-1.jpg')
- gray1 = cv2.cvtColor(img1,cv2.COLOR_BGR2GRAY)
- gray2 = cv2.cvtColor(img2,cv2.COLOR_BGR2GRAY)
- orb = cv2.ORB_create()
- kp1,des1 = orb.detectAndCompute(gray1,None)
- kp2,des2 = orb.detectAndCompute(gray2,None)
- bf = cv2.BFMatcher(cv2.NORM_HAMMING,crossCheck=True)
- matches = bf.match(des1,des2)
- matches = sorted(matches,key=lambda x:x.distance)
- img3 = cv2.drawMatches(img1,kp1,img2,kp2,matches[:80],img2,flags=2)
- plt.figure(figsize=(60,80),dpi=80)
- img_show('',img3)
-
原文链接:https://blog.csdn.net/qq_28368377/article/details/104985249
作者:sjhjf0293
链接:https://www.pythonheidong.com/blog/article/274511/1c5501df28d22f1847bf/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!