OpenCV学习笔记(十三)边缘检测

这篇博客详细介绍了OpenCV中的边缘检测方法,包括Sobel、Laplace、Prewitt、Canny和Marr-Hildreth算子。重点讲解了Sobel算子的原理和使用方法,如参数设置、图像深度处理以及边缘检测的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

边缘检测:

边缘检测算子有很多,Sobel、Laplace、Prewitt、Canny、Marr-Hildresh。

Sobel算子:

Sobel算子是主要用于边缘检测的离散微分算子,它结合了高斯平滑和微分求导,用于计算图像灰度函数的近似梯度。

void Sobel(InputArray src, OutputArray dst, int ddepth, int xorder, int yorder, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )

  • src – Source image.
  • dst – Destination image of the same size and the same number of channels as src .
  • ddepth – Destination image depth.
  • xorder – Order of the derivative x.
  • yorder – Order of the derivative y.
  • ksize – Size of the extended Sobel kernel. It must be 1, 3, 5, or 7.
  • scale – Optional scale factor for the computed derivative values. By default, no scaling is applied. SeegetDerivKernels() for details.
  • delta – Optional delta value that is added to the results prior to storing them in dst .
  • borderType – Pixel extrapolation method. See borderInterpolate() for details.
一般情况下,都是使用ksize*ksize内核计算导数的。当ksize=1时,往往使用3x1或者1x3的内核。
程序实现:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
	Mat gray_x, gray_y;
	Mat abs_gray_x, abs_gray_y, dst;
	Mat srcImage = imread("D:\\3.jpg");
	if (!srcImage.data)
		return -1;
	Mat srcGray;
	cvtColor(srcImage, srcGray, CV_RGB2GRAY);
	imshow("srcGray", srcGray);
	Sobel(srcGray, gray_x, CV_16S, 1, 0, 3, 1, 1, BORDER_DEFAULT);
	convertScaleAbs(gray_x, abs_gray_x);
	im
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值