计算机视觉
图像处理

Opencv实现Canny算子边缘检测

Opencv实现Canny算子边缘检测

void CCVMFCView::OnCannyBorddetec()
{
	IplImage* src = 0;
	IplImage* dst = 0;
	IplImage* color_dst = 0;
	CvMemStorage* storage = cvCreateMemStorage(0);
	CvSeq* lines = 0;
	int i;

	if (workImg->nChannels==3) {
		src = cvCreateImage(cvGetSize(workImg), IPL_DEPTH_8U, 1);
		cvCvtColor(workImg, src, CV_BGR2GRAY);
	}
	else {
		src = cvCloneImage( workImg );
	}
	cvFlip(src);

	dst = cvCreateImage( cvGetSize(src), 8 ,1 );
	color_dst = cvCreateImage( cvGetSize(src), 8, 3 );

	cvCanny( src, dst, 50, 200, 3 );
	cvCvtColor( dst, color_dst, CV_GRAY2BGR );

	cvFlip(color_dst);
	m_dibFlag=imageClone(color_dst,&workImg);
	Invalidate();
}

opencv 动态调节canny参数 边缘检测

void on_trackbar3(int h)
{
	cvCanny( image, cedge, edge_thresh, edge_thresh*3, 3 );
	cvShowImage("Adjust Canny Parameter",cedge);
}

void CCVMFCView::OnCannyAdjThres()
{
	cedge=cvCreateImage(cvGetSize(workImg),workImg->depth,1);
	IplImage* color_dst = 0;
	CvMemStorage* storage = cvCreateMemStorage(0);
	CvSeq* lines = 0;
	int i;

	if (workImg->nChannels==3) {
		image = cvCreateImage(cvGetSize(workImg), IPL_DEPTH_8U, 1);
		cvCvtColor(workImg, image, CV_BGR2GRAY);
	}
	else {
		image = cvCloneImage( workImg );
	}
	cvFlip(image);

	dst = cvCreateImage( cvGetSize(image), 8 ,1 );
	color_dst = cvCreateImage( cvGetSize(image), 8, 3 );
	cvNamedWindow("Adjust Canny Parameter",CV_WINDOW_AUTOSIZE);
	//cvShowImage("Adjust Canny Parameter",image);
	cvCreateTrackbar("canny_thres","Adjust Canny Parameter",&edge_thresh,100,on_trackbar3);
	on_trackbar3(1);
	
	cvWaitKey(0);
	cvDestroyWindow("Adjust Canny Parameter");
	cvCvtColor( cedge, color_dst, CV_GRAY2BGR );
	cvFlip(color_dst);
	m_dibFlag=imageClone(color_dst,&workImg);
	m_ImageType=1;
	Invalidate();
}

转载注明来源:CV视觉网 » Opencv实现Canny算子边缘检测

分享到:更多 ()
扫描二维码,给作者 打赏
pay_weixinpay_weixin

请选择你看完该文章的感受:

0不错 0超赞 0无聊 0扯淡 0不解 0路过

评论 4

评论前必须登录!