main_canny.cpp
Go to the documentation of this file.
1 #include <cstdio>
2 #include <stdlib.h>
3 #include <iostream>
4 #include <string>
5 
6 #include <opencv/cv.h>
7 #include <opencv/highgui.h>
8 #include "tuw_utils/canny.h"
9 
10 void help() {
11  std::cout << "\nThis is a demo that shows an anhanced canny edge detection\n"
12  "Usage: \n"
13  " ./canny file # for a single image\n"
14  " ./canny file # for camera usage\n";
15 }
16 
17 int main ( int argc, char *argv[] ) {
18 
19  cv::VideoCapture cap;
20  cv::Mat imgSrc;
21  cv::Mat imgGray;
22  if ( argc != 2 ) {
23  cap.open ( 0 );
24  if ( !cap.isOpened() ) {
25  std::cout << "***Could not initialize capturing...***\n";
26  help();
27  return -1;
28  }
29  cap.set ( CV_CAP_PROP_FRAME_WIDTH, 800 );
30  cap.set ( CV_CAP_PROP_FRAME_HEIGHT, 600 );
31  std::cout << "Video " <<
32  ": width=" << cap.get ( CV_CAP_PROP_FRAME_WIDTH ) <<
33  ", height=" << cap.get ( CV_CAP_PROP_FRAME_HEIGHT ) <<
34  ", nframes=" << cap.get ( CV_CAP_PROP_FRAME_COUNT ) << std::endl;
35  }
36  if ( !cap.isOpened() ) {
37  printf ( "%s\n", argv[1] );
38  imgSrc = cv::imread ( argv[1] );
39  } else {
40  cap >> imgSrc;
41  }
42  if ( imgSrc.empty() ) {
43  std::cout << "***image...***\n";
44  return -1;
45  }
46  cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
47 
48  cv::Mat imgGauss, imgCanny, imgGradient, imgDirection;
49  cv::namedWindow ( "src",1 );
50  cv::namedWindow ( "img",1 );
51  cv::namedWindow ( "canny",1 );
52  cv::namedWindow ( "gradient",1 );
53  cv::namedWindow ( "direction",1 );
54  do {
55  if ( cap.isOpened() ) {
56  cap >> imgSrc;
57  cv::cvtColor ( imgSrc, imgGray, CV_RGB2GRAY );
58  }
59  if ( imgSrc.empty() ) {
60  continue;
61  }
62  cv::GaussianBlur ( imgGray, imgGauss, cv::Size ( 7,7 ), 1.5, 1.5 );
63  V4R::Canny ( imgGauss, imgCanny, imgGradient, imgDirection, 0, 30, 3 );
64  cv::imshow ( "src", imgGray );
65  cv::imshow ( "img", imgGray );
66  cv::imshow ( "canny", imgCanny );
67  cv::imshow ( "gradient", ( imgGradient*65335/360 ) );
68  cv::imshow ( "direction", ( imgDirection*65335/360 ) );
69  } while ( cv::waitKey ( 30 ) < 0 ) ;
70  // the camera will be deinitialized automatically in VideoCapture destructor
71  return 0;
72 }
73 
void help()
Definition: main_canny.cpp:10
void Canny(const cv::Mat &image, cv::Mat &edges, cv::Mat &gradient, cv::Mat &direction, cv::Mat &sobel_dx, cv::Mat &sobel_dy, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false)
Definition: canny.cpp:363
int main(int argc, char *argv[])
Definition: main_canny.cpp:17


tuw_ellipses
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:42:10