【opencv练习22 - Canny算子 边缘检测】

/*****************************************************
    测试程序 Canny 边缘检测
    时间:2016年8月27日
******************************************************/

// Global variables
Mat src, src_gray;
Mat dst, detected_edges;            //目标,目标边缘

int edgeThresh = 1;                 //边缘阈值
int lowThreshold;                   //最低阈值
int const max_lowThreshold = 100;
int ratio = 3;
int kernel_size = 3;                //核尺寸
const char* window_name = "Edge Map";


static void CannyThreshold(int, void*)
{
    //【1、去噪】
    blur( src_gray, detected_edges, Size(3,3) );

    //【2、Canny】
    //参数:src,dst,low,hight,核尺寸
    Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );

    //【3、目标初始化】
    dst = Scalar::all(0);

    src.copyTo( dst, detected_edges);//【4、复制边缘】
    imshow( window_name, dst );
}


int main(void)
{
  src = imread("YY01.jpg");
  dst.create( src.size(), src.type() );   //【dst空间】

  cvtColor( src, src_gray, COLOR_BGR2GRAY );//【灰度化】
  namedWindow( window_name, WINDOW_AUTOSIZE );

  //【创建控制条】
  createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold );

  // Start
  CannyThreshold(0, 0);
  waitKey(0);

  return 0;
}

这里根据不同的最小阈值参数,获取不同的边缘

这里写图片描述

这里写图片描述

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值