【OpenCV】 ⚠️高手勿入! 半小时学会基本操作 23⚠️ 角点检测
【摘要】
【OpenCV】⚠️高手勿入! 半小时学会基本操作 23⚠️
概述角点检测角点检测代码
概述
OpenCV 是一个跨平台的计算机视觉库, 支持多语言, 功能强大. 今天小白就带大家一起携手...
概述
OpenCV 是一个跨平台的计算机视觉库, 支持多语言, 功能强大. 今天小白就带大家一起携手走进 OpenCV 的世界. (第 23 课)
角点检测
角点检测 (Corner Detection) 是图像的重要特征. 角点可以帮助我们实现图像对其, 图像拼接, 目标识别等等重要用途.
Harris 角点检测 (Harris Corner Detection) 是最基础也是最重要的一种角点检测算法. 通过计算图像在 x, y 上平移的自相似性 (Self-Similarity) 来判断图像是否为角点.
例如: 某图像的某个位置在 x / y 方向上做微小的滑动, 如果窗口内的灰度值都有较大变换, 那么这个位置就是角点.
角点检测代码
格式:
cv2.cornerHarris(src, blockSize, ksize, k, dst=None, borderType=None)
- 1
参数:
- scr: 输入图像
- blockSize: 焦点检测中指定区域的大小
- ksize: Sobel 求导中使用的窗口大小
- ksize: Sobel 孔径参数, 取值范围为 [0.04, 0.06]
例1 :
import numpy as np
import cv2
# 读取图片
image = cv2.imread("house.jpg")
# 转换成灰度图
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# harris角点检测
harris = cv2.cornerHarris(image_gray, 2, 3, 0.04)
# 阈值转换原图
image_corner = image.copy()
image_corner[harris > 0.01 * harris.max()] = [0, 0, 255]
# 整合
combine = np.hstack((image, image_corner))
# 图片展示
cv2.imshow("origional vs corner detection", combine)
cv2.waitKey(0)
cv2.destroyAllWindows()
# 保存结果
cv2.imwrite("harris.jpg", combine)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
输出结果:
例 2:
import numpy as np
import cv2
# 读取图片
image = cv2.imread("house2.jpg")
# 转换成灰度图
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# harris角点检测
harris = cv2.cornerHarris(image_gray, 2, 3, 0.04)
# 阈值转换原图
image_corner = image.copy()
image_corner[harris > 0.1 * harris.max()] = [0, 0, 255]
# 整合
combine = np.hstack((image, image_corner))
# 图片展示
cv2.imshow("origional vs corner detection", image_corner)
cv2.waitKey(0)
cv2.destroyAllWindows()
# 保存结果
cv2.imwrite("harris.jpg", combine)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
输出结果:
文章来源: iamarookie.blog.csdn.net,作者:我是小白呀,版权归原作者所有,如需转载,请联系作者。
原文链接:iamarookie.blog.csdn.net/article/details/119130841
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)