OpenCV 边缘检测

Laplacian算子

#include<opencv2/opencv.hpp>
#include<quickopencv.h>
#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;


int main(int argc, char** argv) {

	Mat img = imread("D:/images/dog.png", IMREAD_ANYDEPTH);
	if (img.empty()) {
		cout << "请确认图像文件名称正确!" << endl;
		return -1;
	}
	Mat result, result_g, result_G;
	//未进行滤波提取Laplacian边缘
	Laplacian(img, result, CV_16S, 3, 1, 0);
	convertScaleAbs(result, result);
	//未进行滤波提取Laplacian边缘
	GaussianBlur(img, result_g, Size(3, 3), 5, 0);		//高斯滤波
	Laplacian(result_g, result_G, CV_16S, 3, 1, 0);
	convertScaleAbs(result_G, result_G);
	imshow("result", result);
	imshow("result_G", result_G);
	waitKey(0);//此时图片显示时间为一直停留。(x)为x毫秒
	destroyAllWindows();
	return 0;
}

canny算法

#include<opencv2/opencv.hpp>
#include<quickopencv.h>
#include<iostream>
#include<math.h>
using namespace cv;
using namespace std;


int main(int argc, char** argv) {

	Mat img = imread("D:/images/dog.png", IMREAD_ANYDEPTH);
	if (img.empty()) {
		cout << "请确认图像文件名称正确!" << endl;
		return -1;
	}
	Mat resultH, resultL, resultG;
	//高阈值检测图像边缘
	Canny(img, resultH, 100, 200, 3);
	//低阈值检测图像边缘
	Canny(img, resultL, 20, 40, 3);
	//高斯模糊后检测图像边缘
	GaussianBlur(img, resultG, Size(3, 3), 5);
	Canny(resultG, resultG, 100, 200, 3);
	imshow("resultH", resultH);
	imshow("resultL", resultL);
	imshow("resultG", resultG);
	waitKey(0);//此时图片显示时间为一直停留。(x)为x毫秒
	destroyAllWindows();
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值