opencv-canny边缘检测
2013-03-27 22:30
417 查看
#include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <stdlib.h> #include <stdio.h> #include <iostream> using namespace cv; using namespace std; //全局变量 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"; /* * @function CannyThreshold * @brief Trackbar callback - Canny thresholds input with a ratio 1:3 */ static void CannyThreshold(int, void*) { /// Reduce noise with a kernel 3x3 blur( src_gray, detected_edges, Size(3,3) ); /// Canny detector Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size ); /// Using Canny's output as a mask, we display our result dst = Scalar::all(0); src.copyTo( dst, detected_edges); imshow( window_name, dst ); } /** * @function main */ int main( int, char** argv ) { /// Load an image //src = imread( argv[1] ); src = imread("D:\\原始lena图像.bmp",CV_LOAD_IMAGE_COLOR); if( !src.data ) { return -1; } /// Create a matrix of the same type and size as src (for dst) dst.create( src.size(), src.type() ); /// Convert the image to grayscale cvtColor( src, src_gray, CV_BGR2GRAY ); /// Create a window namedWindow( window_name, CV_WINDOW_AUTOSIZE ); /// Create a Trackbar for user to enter threshold createTrackbar( "Min Threshold:", window_name, &lowThreshold, max_lowThreshold, CannyThreshold ); /// Show the image CannyThreshold(0, 0); /// Wait until user exit program by pressing a key waitKey(0); return 0; }
相关文章推荐
- OpenCV学习笔记(三):Canny边缘检测和滚动条制作
- OpenCV笔记:图像边缘检测Sobel,Laplace,Canny
- [学习OpenCV攻略][008][Canny边缘检测]
- 基于OpenCV的canny边缘检测的MFC实现
- Android opencv(三) 边缘检测Sobel、Canny
- [Opencv入门笔记] 写图像—Canny边缘检测
- opencv-python 应用滑动条改变canny边缘检测的阈值
- OpenCV: Canny边缘检测算法原理及其VC实现详解
- opencv之canny边缘检测
- opencv边缘检测Sobel和Canny
- 【OpenCV】3rd-Canny边缘检测、打开摄像头
- OpenCV人脸跟踪canny边缘检测
- [Opencv入门笔记] 写图像—Canny边缘检测
- OpenCV(学习笔记5)-Canny边缘检测
- 图像处理--opencv2 canny边缘检测
- opencv的Sobel导数、Scharr滤波器、Laplacian算子、Canny边缘检测
- OpenCV参考手册之Canny边缘检测
- 【OpenCV】Canny 边缘检测
- OpenCV2.4.10之samples_cpp_tutorial-code_learn-----ImgTrans(Canny边缘检测)
- 【OpenCV入门指南】第三篇Canny边缘检测