当前位置:网站首页>opencv学习笔记五——梯度计算/边缘检测
opencv学习笔记五——梯度计算/边缘检测
2022-07-07 05:19:00 【我是一个小稻米】
要获取轮廓,可对一张图像做先膨胀后腐蚀的操作,然后膨胀后的结果减去腐蚀的结果。
1. Sobel
算子
dst = cv2.Sobel(src, ddepth, dx, dy, ksize)
ddepth
:图像的深度dx
核dy
分别表示水平和垂直方向ksize
是Sobel
算子大小
image1 = cv2.imread('./ro.png')
plt.imshow(image1);
image1 = cv2.imread('./ro.png')
plt.imshow(image1);
image2 = cv2.Sobel(image1, cv2.CV_64F, 1, 0, ksize=3)
plt.imshow(image2);
白到黑的卷积计算是正数,黑到白的卷积计算就是负值了,所有的负数会被截断为0
,所以要取绝对值
计算x
方向梯度
image2 = cv2.Sobel(image1, cv2.CV_64F, 1, 0, ksize=3)
image2 = cv2.convertScaleAbs(image2)
plt.imshow(image2);
计算x
方向梯度
image3 = cv2.Sobel(image1, cv2.CV_64F, 0, 1, ksize=3)
image3 = cv2.convertScaleAbs(image3)
plt.imshow(image3);
获得图像的轮廓
image4 = cv2.addWeighted(image2, 0.5, image3, 0.5, 0)
plt.imshow(image4);
换一张图试试
import cv2
import matplotlib.pyplot as plt
image = cv2.imread('image.png')
image2 = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3)
image2 = cv2.convertScaleAbs(image2)
image3 = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3)
image3 = cv2.convertScaleAbs(image3)
image4 = cv2.addWeighted(image2, 0.5, image3, 0.5, 0)
image4 = cv2.cvtColor(image4, cv2.COLOR_BGR2RGB)
plt.imshow(image4);
2. Scharr
算子
用法相同,只是计算的值会比较大,会更敏感些
3. laplacian
算子
边栏推荐
- JS cross browser parsing XML application
- Offer harvester: add and sum two long string numbers (classic interview algorithm question)
- Recursive method constructs binary tree from middle order and post order traversal sequence
- Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
- 在Rainbond中一键部署高可用 EMQX 集群
- Vulnerability recurrence easy_ tornado
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- 漏洞複現-Fastjson 反序列化
- eBPF Cilium实战(1) - 基于团队的网络隔离
- Uniapp mobile terminal forced update function
猜你喜欢
【數字IC驗證快速入門】15、SystemVerilog學習之基本語法2(操作符、類型轉換、循環、Task/Function...內含實踐練習)
央视太暖心了,手把手教你写HR最喜欢的简历
[quickstart to Digital IC Validation] 15. Basic syntax for SystemVerilog Learning 2 (operator, type conversion, loop, Task / Function... Including practical exercises)
快解析内网穿透为文档加密行业保驾护航
解读创客思维与数学课程的实际运用
饥荒云服管理脚本
【数字IC验证快速入门】13、SystemVerilog interface 和 program 学习
Yugu p1020 missile interception (binary search)
发挥创客教育空间的广泛实用性
jeeSite 表单页面的Excel 导入功能
随机推荐
The legend about reading the configuration file under SRC
Battery and motor technology have received great attention, but electric control technology is rarely mentioned?
王爽 《汇编语言》之寄存器
Find the mode in the binary search tree (use medium order traversal as an ordered array)
Recursive method to construct binary tree from preorder and inorder traversal sequence
LeetCode简单题之找到一个数字的 K 美丽值
B. Value sequence thinking
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
LeetCode简单题之字符串中最大的 3 位相同数字
jeeSite 表单页面的Excel 导入功能
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
使用 Nocalhost 开发 Rainbond 上的微服务应用
Niu Mei's mathematical problem --- combinatorial number
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Relevant data of current limiting
Rainbond 5.6 版本发布,增加多种安装方式,优化拓扑图操作体验
Blob object introduction
Unityhub cracking & unity cracking
The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
buureservewp(2)