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展示动态规则法用以解决重叠子问题的示例
Apr 02 Python
Python实现Sqlite将字段当做索引进行查询的方法
Jul 21 Python
Python实现随机生成有效手机号码及身份证功能示例
Jun 05 Python
Python中摘要算法MD5,SHA1简介及应用实例代码
Jan 09 Python
Python 获得命令行参数的方法(推荐)
Jan 24 Python
Python Requests模拟登录实现图书馆座位自动预约
Apr 27 Python
python numpy 显示图像阵列的实例
Jul 02 Python
Pytorch 保存模型生成图片方式
Jan 10 Python
tensorflow保持每次训练结果一致的简单实现
Feb 17 Python
Python 中由 yield 实现异步操作
May 04 Python
在Django中自定义filter并在template中的使用详解
May 19 Python
python打开文件的方式有哪些
Jun 29 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在Web开发领域的优势
2006/10/09 PHP
php批量缩放图片的代码[ini参数控制]
2011/02/11 PHP
php数组去除空值函数分享
2015/02/02 PHP
PHP实现文字写入图片功能
2019/02/18 PHP
JavaScript通过RegExp实现客户端验证处理程序
2013/05/07 Javascript
JS中类或对象的定义说明
2014/03/10 Javascript
javascript设计模式之对象工厂函数与构造函数详解
2015/07/30 Javascript
深入理解JavaScript单体内置对象
2016/06/06 Javascript
微信小程序 摇一摇抽奖简单实例实现代码
2017/01/09 Javascript
jQuery表单元素选择器代码实例
2017/02/06 Javascript
Vue中常用rules校验规则(实例代码)
2019/11/14 Javascript
vue项目中使用多选框的实例代码
2020/07/22 Javascript
基于Vue+Webpack拆分路由文件实现管理
2020/11/16 Javascript
vue 表单输入框不支持focus及blur事件的解决方案
2020/11/17 Vue.js
Django 导出 Excel 代码的实例详解
2017/08/11 Python
NumPy 如何生成多维数组的方法
2018/02/05 Python
python 请求服务器的实现代码(http请求和https请求)
2018/05/25 Python
Python使用cx_Freeze库生成msi格式安装文件的方法
2018/07/10 Python
python3实现字符串操作的实例代码
2019/04/16 Python
Python中如何导入类示例详解
2019/04/17 Python
浅谈Pytorch torch.optim优化器个性化的使用
2020/02/20 Python
django使用F方法更新一个对象多个对象字段的实现
2020/03/28 Python
python给视频添加背景音乐并改变音量的具体方法
2020/07/19 Python
英国领先的名牌服装折扣零售商:Brown Bag Clothing
2019/01/08 全球购物
美国和加拿大计算机和电子产品购物网站:TigerDirect.com
2019/09/13 全球购物
澳大利亚著名的纺织品品牌:Canningvale
2020/05/05 全球购物
附答案的Java面试题
2012/11/19 面试题
会计学财务管理专业个人的自我评价
2013/10/19 职场文书
研究生自我鉴定范文
2013/10/30 职场文书
求职面试个人自我评价
2014/02/28 职场文书
见习报告怎么写
2014/10/31 职场文书
群众路线教育实践活动调研报告
2014/11/03 职场文书
锦旗赠语
2015/06/23 职场文书
导游词之张家口
2019/12/13 职场文书
python爬取企查查企业信息之selenium自动模拟登录企查查
2021/04/08 Python
Shell中的单中括号和双中括号的用法详解
2022/12/24 Servers