图像处理---《Canny 边缘检测》
很想系统的把图像处理之边缘检测部分详细的过一遍,对比一个各个算子的优良性能。时间紧,精力有限,现在只能走哪补哪,随手记。
有几个简单的场景,有需要,想通过图像的边缘特征区分开。解决问题的方法有很多,知识储备有限,最先想到Canny、Sobel算子,
其实对这两个也不熟,现琢磨现用,希望对解决问题有帮助。这里记一下,Canny 边缘检测的效果。
/*作者:WP @0620功能:检测车道线---Canny算法说明:先利用轨迹条选一个较好的lowThreshold值,Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );参考:《Canny 边缘检测》.cn/opencvdoc/2.3.2/html/doc/tutorials/imgproc/imgtrans/canny_detector/canny_detector.html *///-----------------------------------【头文件包含部分】-----------------------------------------------------------------------// 描述:包含程序所依赖的头文件//----------------------------------------------------------------------------------------------------------------------------#include <opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>using namespace std;using namespace cv;//Canny边缘检测算法int main(){Mat img = imread("D:\\003_test_img\\test002_VS\\013_7.png");imshow("原始图", img);Mat DstPic, edge, grayImage;//创建与src同类型和同大小的矩阵 DstPic.create(img.size(), img.type());//将原始图转化为灰度图 cvtColor(img, grayImage, COLOR_BGR2GRAY);//先使用3*3内核来降噪blur(grayImage, edge, Size(3, 3));//运行canny算子//Canny(edge, edge, 3, 3*3, 3);Canny(edge, edge, 160, 160*3, 3);imshow("边缘提取效果", edge);waitKey(0);}