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读取html中指定元素生成excle文件示例
Apr 03 Python
python通过BF算法实现关键词匹配的方法
Mar 13 Python
Python中max函数用法实例分析
Jul 17 Python
python实现SOM算法
Feb 23 Python
关于python2 csv写入空白行的问题
Jun 22 Python
matplotlib调整子图间距,调整整体空白的方法
Aug 03 Python
python正则表达式匹配不包含某几个字符的字符串方法
Jul 23 Python
Python 继承,重写,super()调用父类方法操作示例
Sep 29 Python
PIL包中Image模块的convert()函数的具体使用
Feb 26 Python
python GUI库图形界面开发之PyQt5结合Qt Designer创建信号与槽的详细方法与实例
Mar 08 Python
利用python查看数组中的所有元素是否相同
Jan 08 Python
Django项目配置Memcached和Redis, 缓存选择哪个更有优势
Apr 06 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
Win2000+Apache+MySql+PHP4+PERL安装使用小结
2006/10/09 PHP
array_multisort实现PHP多维数组排序示例讲解
2011/01/04 PHP
php whois查询API制作方法
2011/06/23 PHP
PHP转换文件夹下所有文件编码的实现代码
2013/06/06 PHP
PHP实现的蚂蚁爬杆路径算法代码
2015/12/03 PHP
PHP开发之归档格式phar文件概念与用法详解【创建,使用,解包还原提取】
2017/11/17 PHP
ThinkPHP框架结合Ajax实现用户名校验功能示例
2019/07/03 PHP
PHP针对redis常用操作实例详解
2019/08/17 PHP
Javascript面向对象扩展库代码分享
2012/03/27 Javascript
jquery div 居中技巧应用介绍
2012/11/24 Javascript
利用jquery操作Radio方法小结
2014/10/20 Javascript
比较常见的javascript中定义函数的区别
2015/11/09 Javascript
JavaScript深度复制(deep clone)的实现方法
2016/02/19 Javascript
详解使用jest对vue项目进行单元测试
2018/09/07 Javascript
JS将时间秒转换成天小时分钟秒的字符串
2019/07/10 Javascript
vue中echarts引入中国地图的案例
2020/07/28 Javascript
JS+css3实现幻灯片轮播图
2020/08/14 Javascript
合并Excel工作薄中成绩表的VBA代码,非常适合教育一线的朋友
2009/04/09 Python
Python实现多行注释的另类方法
2014/08/22 Python
Python中的random.uniform()函数教程与实例解析
2019/03/02 Python
django rest framework serializers序列化实例
2020/05/13 Python
Django自关联实现多级联动查询实例
2020/05/19 Python
如何用python开发Zeroc Ice应用
2021/01/29 Python
用html5的canvas和JavaScript创建一个绘图程序的简单实例
2016/07/06 HTML / CSS
DAWGS鞋官方网站:鞋,凉鞋,靴子
2016/10/04 全球购物
教师自荐书
2013/10/08 职场文书
大学生毕业鉴定
2014/01/31 职场文书
一岗双责责任书
2014/04/15 职场文书
心理学专业求职信
2014/06/16 职场文书
校庆标语集锦
2014/06/25 职场文书
党的群众路线教育实践活动心得体会范文
2014/11/05 职场文书
个人工作表现自我评价
2015/03/06 职场文书
三国演义读书笔记
2015/06/25 职场文书
python读取pdf格式文档的实现代码
2021/04/01 Python
在js中修改html body的样式
2021/11/11 Javascript
3050和2060哪个好 性能差多少 差距有多大 谁更有性价比
2022/06/17 数码科技