OpenCV哈里斯(Harris)角点检测的实现
技术  /  管理员 发布于 7年前   337
环境
pip install opencv-python==3.4.2.16 pip install opencv-contrib-python==3.4.2.16
理论
克里斯・哈里斯(Chris Harris)和迈克・史蒂芬斯(Mike Stephens)在1988年的论文《组合式拐角和边缘检测器》中做了一次尝试找到这些拐角的尝试,所以现在将其称为哈里斯拐角检测器。
函数:cv2.cornerHarris(),cv2.cornerSubPix()
示例代码
import cv2import numpy as np filename = 'molecule.png'img = cv2.imread(filename)gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gray = np.float32(gray)dst = cv2.cornerHarris(gray,2,3,0.04) #result is dilated for marking the corners, not importantdst = cv2.dilate(dst,None) # Threshold for an optimal value, it may vary depending on the image.img[dst>0.01*dst.max()]=[0,0,255] cv2.imshow('dst',img)if cv2.waitKey(0) & 0xff == 27: cv2.destroyAllWindows()
原图
输出图
SubPixel精度的角落
import cv2import numpy as np filename = 'molecule.png'img = cv2.imread(filename)gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # find Harris cornersgray = np.float32(gray)dst = cv2.cornerHarris(gray,2,3,0.04)dst = cv2.dilate(dst,None)ret, dst = cv2.threshold(dst,0.01*dst.max(),255,0)dst = np.uint8(dst) # find centroidsret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst) # define the criteria to stop and refine the cornerscriteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.001)corners = cv2.cornerSubPix(gray,np.float32(centroids),(5,5),(-1,-1),criteria) # Now draw themres = np.hstack((centroids,corners))res = np.int0(res)img[res[:,1],res[:,0]]=[0,0,255]img[res[:,3],res[:,2]] = [0,255,0] cv2.imwrite('subpixel5.png',img)
输出图
参考
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html#harris-corners
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号