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

作者:qq2648008726 时间:2022-10-07 01:41:26 

环境


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

来源:https://blog.csdn.net/u012325865/article/details/103044562

标签:OpenCV,角点检测
0
投稿

猜你喜欢

  • Symfony2之session与cookie用法小结

    2023-11-22 02:58:30
  • Vue+ECharts实现中国地图的绘制及各省份自动轮播高亮显示

    2024-04-27 16:12:40
  • 浅析JavaScript对象转换成原始值

    2023-08-05 02:09:11
  • vue中的stylus及stylus-loader版本问题

    2023-07-02 16:32:20
  • 如何用Python和JS实现的Web SSH工具

    2021-04-23 13:50:13
  • display:inline-block的深入理解

    2007-05-11 17:03:00
  • 高性能JavaScript模板引擎实现原理详解

    2024-04-18 09:37:11
  • python创建一个最简单http webserver服务器的方法

    2021-12-15 03:45:40
  • Mysql官方性能测试工具mysqlslap的使用简介

    2024-01-23 18:38:46
  • JS中ESModule和commonjs介绍及使用区别

    2023-10-20 22:23:51
  • python实现将元祖转换成数组的方法

    2022-11-22 02:40:32
  • python实现决策树

    2021-11-07 19:14:05
  • sql server 触发器实例代码

    2012-01-05 19:09:28
  • 详解python uiautomator2 watcher的使用方法

    2022-03-04 07:31:23
  • 小白教程|一小时上手最流行的前端框架vue(推荐)

    2024-04-30 10:34:20
  • Python3 适合初学者学习的银行账户登录系统实例

    2021-06-16 05:09:22
  • python中的tkinter库弹窗messagebox详解

    2023-11-12 04:02:05
  • JS简单的轮播的图片滚动实例

    2024-03-19 19:46:31
  • MySql如何获取相邻数据

    2024-01-16 04:36:53
  • Varchar与char的区别

    2008-02-28 12:44:00
  • asp之家 网络编程 m.aspxhome.com