[Opencv] 2. Edge Detection

Source: Internet
Author: User

 

>_< "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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.