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 相关文章推荐
可用于监控 mysql Master Slave 状态的python代码
Feb 10 Python
windows下cx_Freeze生成Python可执行程序的详细步骤
Oct 09 Python
使用python判断你是青少年还是老年人
Nov 29 Python
Python 存储字符串时节省空间的方法
Apr 23 Python
python实现对象列表根据某个属性排序的方法详解
Jun 11 Python
python中的反斜杠问题深入讲解
Aug 12 Python
Python递归函数 二分查找算法实现解析
Aug 12 Python
python中前缀运算符 *和 **的用法示例详解
May 28 Python
Python设计密码强度校验程序
Jul 30 Python
python 中的9个实用技巧,助你提高开发效率
Aug 30 Python
我对PyTorch dataloader里的shuffle=True的理解
May 20 Python
python函数的两种嵌套方法使用
Apr 02 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中使用GD库创建圆形饼图的例子
2014/11/19 PHP
详解WordPress中提醒安装插件以及隐藏插件的功能实现
2015/12/25 PHP
PHP 在数组中搜索给定的简单实例 array_search 函数
2016/06/13 PHP
PHP验证终端类型是否为手机的简单实例
2017/02/07 PHP
laravel框架中间件 except 和 only 的用法示例
2019/07/12 PHP
获取dom元素那些讨厌的位置封装代码
2010/06/23 Javascript
精心挑选的12款优秀的基于jQuery的手风琴效果插件和教程
2012/08/22 Javascript
jQuery动态设置form表单的enctype值(实现代码)
2013/07/04 Javascript
js css 实现遮罩层覆盖其他页面元素附图
2014/09/22 Javascript
JS实现FLASH幻灯片图片切换效果的方法
2015/03/04 Javascript
JS折半插入排序算法实例
2015/12/02 Javascript
JS表格组件神器bootstrap table详解(基础版)
2015/12/08 Javascript
Bootstrap按钮组件详解
2016/04/26 Javascript
jQuery弹出下拉列表插件(实现kindeditor的@功能)
2016/08/16 Javascript
vue的一个分页组件的示例代码
2017/12/25 Javascript
微信小程序实现指定显示行数多余文字去掉用省略号代替
2018/07/25 Javascript
jQuery Ajax实现Select多级关联动态绑定数据的实例代码
2018/10/26 jQuery
vue使用Google地图的实现示例代码
2018/12/19 Javascript
vue中实现回车键登录功能
2020/02/19 Javascript
[01:15:36]加油刀塔第二期网络版
2014/08/09 DOTA
Python中的匿名函数使用简介
2015/04/27 Python
python爬虫headers设置后无效的解决方法
2017/10/21 Python
浅谈numpy数组中冒号和负号的含义
2018/04/18 Python
使用python对多个txt文件中的数据进行筛选的方法
2019/07/10 Python
Python使用__new__()方法为对象分配内存及返回对象的引用示例
2019/09/20 Python
Python with标签使用方法解析
2020/01/17 Python
Python argparse模块使用方法解析
2020/02/20 Python
pyCharm 设置调试输出窗口中文显示方式(字符码转换)
2020/06/09 Python
英国时尚首饰品牌:Missoma
2020/06/29 全球购物
影子教师研修方案
2014/06/14 职场文书
党员作风建设自查报告
2014/10/23 职场文书
教师党员群众路线教育实践活动心得体会
2014/11/04 职场文书
2015年物业管理工作总结
2015/04/23 职场文书
幼儿园小班工作总结2015
2015/04/25 职场文书
mysql 直接拷贝data 目录下文件还原数据的实现
2021/07/25 MySQL
Python使用PyYAML库读写yaml文件的方法
2022/04/06 Python