OpenCV哈里斯(Harris)角点检测的实现
作者:qq2648008726 发布时间:2022-10-07 01:41:26
标签:OpenCV,角点检测
环境
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()
原图
输出图
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)
输出图
参考
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_feature2d/py_features_harris/py_features_harris.html#harris-corners
来源:https://blog.csdn.net/u012325865/article/details/103044562
0
投稿
猜你喜欢
- 在认识ImageMagick之前,我使用的图像浏览软件是KuickShow,截图软件是KSnapShot,这两款软件都是KDE附带的软件,用
- 引言python编程时,一部分人习惯将实现同一个功能的代码放在同一个文件;使用这些代码只需要import就可以了;下面看一个例子。testM
- 有时候我们需要使用python执行一些脚本,可能需要让程序自动按键或自动点击鼠标,下面的代码实现了对键盘的模拟按键,需要安装pypiwin3
- 本文以实例演示5种验证码,并介绍生成验证码的函数。PHP生成验证码的原理:通过GD库,生成一张带验证码的图片,并将验证码保存在Session
- 这篇文章所说的视觉元素是指:在一个网站中除去内容(文本、图片、视频、音频等)之外的一些元素。比如图标,背景色,以及背景图案。视觉元素的设计是
- Css tranistions允许元素的属性在单位时间内发生平滑的过渡,在阅读完《CSS Transitions Module Level
- 在命令行中使用 Python 时,它可以接收大约 20 个选项(option),语法格式如下:python [-bBdEhiIOqsSuvV
- 在SQL查询中,关键词Like可提供模糊查询功能,它通常与通配符一起使用。1 Like条件适用数据库字段类型 &nbs
- adfuller函数返回值的参数说明from statsmodels.tsa.stattools import adfullert = ad
- python3下载抖音视频的代码如下所示:# -*- coding:utf-8 -*-from contextlib import clos
- 一、安装Bautiful Soup 是第三方库,因此需要单独下载,下载方式非常简单由于 BS4 解析页面时需要依赖文档解析器,所以还需要安装
- 一、前言在本系列前面几篇文章中,我们分别介绍了 argparse 和 docopt 的主要功能和用法。它们各具特色,都能出色地完成命令行任务
- 实例如下:# -*- coding: utf-8 -*-"""Spyder EditorThis tempor
- 一.环境变量右键我的电脑–>>属性–>>高级系统设置–&
- 设计师在抱怨开发人员不尊重Web标准,后台开发人员在抱怨为什么不可以增加一个空格。PM在抱怨为什么项目总是因为那些看似简单的问题而延期……如
- 如何在线修改表?具体代码如下:<%Set conn1 = Server.CreateObject(&qu
- import random, stringclass C(object): passdef danger
- 注意事项:1.PyCharm尽量在官网下载:https://www.jetbrains.com/pycharm/download/也可以用本
- jupyter notebookjupyter不被识别为内部或外部命令,可操作程序或批处理文件'上次 jupyter noteboo
- 一、ASP的平反想到ASP 很多人会说 “asp语言很蛋疼,不能面向对象,功能单一,很多东西实现不了” 等等诸如此类。 以上说法都是错误的,