当前位置:网站首页>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
算子
边栏推荐
猜你喜欢
Interactive book delivery - signed version of Oracle DBA work notes
Rainbond结合NeuVector实践容器安全管理
Codeforce c.strange test and acwing
2022 Inner Mongolia latest advanced fire facility operator simulation examination question bank and answers
Implementation of replacement function of shell script
使用 Nocalhost 开发 Rainbond 上的微服务应用
Game attack and defense world reverse
JS quick start (I)
云原生存储解决方案Rook-Ceph与Rainbond结合的实践
在Rainbond中实现数据库结构自动化升级
随机推荐
Jmeter 的使用
Explore dry goods! Apifox construction ideas
Real time monitoring of dog walking and rope pulling AI recognition helps smart city
柯基数据通过Rainbond完成云原生改造,实现离线持续交付客户
Network learning (I) -- basic model learning
Bayes' law
Pytorch(六) —— 模型调优tricks
offer收割机:两个长字符串数字相加求和(经典面试算法题)
快解析内网穿透为文档加密行业保驾护航
Main window in QT learning 27 application
ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
eBPF Cilium实战(1) - 基于团队的网络隔离
发挥创客教育空间的广泛实用性
Qinglong panel -- finishing usable scripts
Topic not received? Try this
The element with setfieldsvalue set is obtained as undefined with GetFieldValue
Rainbond结合NeuVector实践容器安全管理
漏洞复现-Fastjson 反序列化
面试题(CAS)
Merging binary trees by recursion