OpenCV哈里斯(Harris)角点检测的实现


Posted in Python onJanuary 15, 2020

环境

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 cv2
import 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 important
dst = 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()

原图

OpenCV哈里斯(Harris)角点检测的实现

输出图

OpenCV哈里斯(Harris)角点检测的实现

SubPixel精度的角落

import cv2
import numpy as np
 
filename = 'molecule.png'
img = cv2.imread(filename)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
 
# find Harris corners
gray = 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 centroids
ret, labels, stats, centroids = cv2.connectedComponentsWithStats(dst)
 
# define the criteria to stop and refine the corners
criteria = (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 them
res = 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)

输出图

OpenCV哈里斯(Harris)角点检测的实现

参考

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html#harris-corners

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python实现批量读取word中表格信息的方法
Jul 30 Python
Python iter()函数用法实例分析
Mar 17 Python
Python功能点实现:函数级/代码块级计时器
Jan 02 Python
PyQt5 实现给窗口设置背景图片的方法
Jun 13 Python
Tensorflow实现酸奶销量预测分析
Jul 19 Python
Python一键查找iOS项目中未使用的图片、音频、视频资源
Aug 12 Python
基于Python新建用户并产生随机密码过程解析
Oct 08 Python
python数值基础知识浅析
Nov 19 Python
使用matplotlib绘制图例标签中带有公式的图
Dec 13 Python
Python实现猜年龄游戏代码实例
Mar 25 Python
matplotlib 对坐标的控制,加图例注释的操作
Apr 17 Python
pytest配置文件pytest.ini的详细使用
Apr 17 Python
Pytorch模型转onnx模型实例
Jan 15 #Python
Python通过TensorFLow进行线性模型训练原理与实现方法详解
Jan 15 #Python
详解Python实现进度条的4种方式
Jan 15 #Python
pytorch常见的Tensor类型详解
Jan 15 #Python
pytorch 常用线性函数详解
Jan 15 #Python
python3.8下载及安装步骤详解
Jan 15 #Python
浅谈pytorch、cuda、python的版本对齐问题
Jan 15 #Python
You might like
用PHP制作静态网站的模板框架(四)
2006/10/09 PHP
php自动更新版权信息显示的方法
2015/06/19 PHP
php生成带logo二维码方法小结
2016/04/08 PHP
PHP+redis实现的限制抢购防止商品超发功能详解
2019/09/19 PHP
filters.revealTrans.Transition使用方法小结
2010/08/19 Javascript
JQuery ztree带筛选、异步加载实例讲解
2016/02/25 Javascript
JavaScript预解析及相关技巧分析
2016/04/21 Javascript
微信小程序进行微信支付的步骤昂述
2016/12/01 Javascript
JavaScript实现Fly Bird小游戏
2016/12/15 Javascript
URL中“#” “?” &“”号的作用浅析
2017/02/04 Javascript
web前端页面生成exe可执行文件的方法
2018/02/08 Javascript
setTimeout时间设置为0详细解析
2018/03/13 Javascript
微信小程序项目实践之主页tab选项实现
2018/07/18 Javascript
Nodejs使用Mongodb存储与提供后端CRD服务详解
2018/09/04 NodeJs
TypeScript中的方法重载详解
2019/04/12 Javascript
浅谈对于“不用setInterval,用setTimeout”的理解
2019/08/28 Javascript
node.JS事件机制与events事件模块的使用方法详解
2020/02/06 Javascript
[03:03]DOTA2 2017国际邀请赛开幕战队入场仪式
2017/08/09 DOTA
python创建关联数组(字典)的方法
2015/05/04 Python
详解Python函数可变参数定义及其参数传递方式
2017/08/02 Python
Python实现购物车功能的方法分析
2017/11/10 Python
Python爬虫天气预报实例详解(小白入门)
2018/01/24 Python
python主线程与子线程的结束顺序实例解析
2019/12/17 Python
自学python用什么系统好
2020/06/23 Python
图片上传插件ImgUploadJS:用HTML5 File API 实现截图粘贴上传、拖拽上传
2016/01/20 HTML / CSS
HTML5之tabindex属性全面解析
2016/07/07 HTML / CSS
HTML5新增加的功能详解
2016/09/05 HTML / CSS
英国儿童鞋和靴子:Start-Rite
2019/05/06 全球购物
行政人事经理职位说明书
2014/03/05 职场文书
物业管理专业求职信
2014/06/11 职场文书
电子商务求职信
2014/06/15 职场文书
电气自动化求职信
2014/06/24 职场文书
地理科学专业自荐信
2014/09/01 职场文书
MySQL之DML语言
2021/04/05 MySQL
mybatis3中@SelectProvider传递参数方式
2021/08/04 Java/Android
Python制作春联的示例代码
2022/01/22 Python