>_< "Edge detection code:
1 # include "opencv2/imgproc. HPP "2 # include" opencv2/highgui. HPP "3 4 # include <stdio. h> 5 6 using namespace CV; 7 using namespace STD; 8 9 int edgethresh = 1; 10 mat image, gray, edge, cedge; 11 12 // define a trackbar callback13 void ontrackbar (INT, void *) 14 {15 blur (Gray, edge, size (3, 3 )); 16 17 // run the edge detector on grayscale18 (edge, edge, edgethresh, edgethresh * 3, 3); 1 9 cedge = scalar: All (0); 20 21 image. copyto (cedge, edge); 22 imshow ("Edge Map", cedge); 23} 24 25 int main (INT argc, const char ** argv) 26 {27 28 image = imread ("fruits.jpg", 1); // read the image to mat29 cedge. create (image. size (), image. type (); // use an image to generate a cedge30 // void cvcvtcolor (const cvarr * SRC, cvarr * DST, int Code); 31 // SRC input 8-bit, 16-bit or 32-Bit Single-precision floating-point image. 32 // DST output 8-bit, 16-bit or 32-bit single precision Floating Point image. 33 // code color space conversion, by defining the CV _ <src_color_space> 2 <dst_color_space> constant (see below ). 34 // function cvcvtcolor converts an input image from a color space to another color space. 35 cvtcolor (image, gray, cv_bgr2gray); // convert to grayscale [color space conversion] 36 37 // create a window38 namedwindow ("Edge Map", 1 ); 39 // create a toolbar40 createtrackbar ("kan threshold", "Edge Map", & edgethresh, 100, ontrackbar); 41 // show the image42 ontrackbar (0, 0 ); 43 44 // wait for a key stroke; the same function arranges events processing45 waitkey (0); 46 Return 0; 47}
[Opencv] 2. Edge Detection