0
点赞
收藏
分享

微信扫一扫

C语言之快速排序

文章目录

Canny 算子算法介绍

非最大信号抑制

高低阈值输出二值图像

Canny 算子

void Canny( InputArray image, OutputArray edges,double threshold1, double threshold2,int apertureSize = 3, bool L2gradient = false );
/*******************************************************************
*			src: 			输入图				
*			edges:	        输出图
*			threshold1:		第一个阈值
*			threshold2:  	第二个阈值
*			apertureSize:	内核大小
*			L2gradient:		计算图像梯度幅值方法的标志
*********************************************************************/

示例

#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>

using namespace cv;
Mat src, gray_src, dst;
int t1_value = 50;
int max_value = 255;
const char* OUTPUT_TITLE = "Canny Result";
void Canny_Demo(int, void*);
int main(int argc, char** argv) {
	src = imread("D:/vcprojects/images/lena.png");
	if (!src.data) {
		printf("could not load image...\n");
		return -1;
	}

	char INPUT_TITLE[] = "input image";
	namedWindow(INPUT_TITLE);
	imshow(INPUT_TITLE, src);

	cvtColor(src, gray_src, CV_BGR2GRAY);//灰度处理
	createTrackbar("Threshold Value:", OUTPUT_TITLE, &t1_value, max_value, Canny_Demo);
	Canny_Demo(0, 0);

	waitKey(0);
	return 0;
}

void Canny_Demo(int, void*) {
	Mat edge_output;
	blur(gray_src, gray_src, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);//模糊降噪
	Canny(gray_src, edge_output, t1_value, t1_value * 2, 3, false);//提取边缘
	//dst.create(src.size(), src.type());
	//src.copyTo(dst, edge_output);
	// (edge_output, edge_output);
	imshow(OUTPUT_TITLE, ~edge_output);
}
举报

相关推荐

0 条评论