Morphology_2.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
33 #include "opencv2/imgproc/imgproc.hpp"
34 #include "opencv2/highgui/highgui.hpp"
35 #include <stdlib.h>
36 #include <stdio.h>
37 
38 using namespace cv;
39 
41 Mat src, dst;
42 
43 int morph_elem = 0;
44 int morph_size = 0;
46 int const max_operator = 4;
47 int const max_elem = 2;
48 int const max_kernel_size = 21;
49 
50 const char* window_name = "Morphology Transformations Demo";
51 
52 
54 void Morphology_Operations( int, void* );
55 
59 int main( int, char** argv )
60 {
62  src = imread( argv[1] );
63 
64  if( !src.data )
65  { return -1; }
66 
68  namedWindow( window_name, WINDOW_AUTOSIZE );
69 
71  createTrackbar("Operator:\n 0: Opening - 1: Closing \n 2: Gradient - 3: Top Hat \n 4: Black Hat", window_name, &morph_operator, max_operator, Morphology_Operations );
72 
74  createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name,
77 
79  createTrackbar( "Kernel size:\n 2n +1", window_name,
82 
84  Morphology_Operations( 0, 0 );
85 
86  waitKey(0);
87  return 0;
88 }
89 
93 void Morphology_Operations( int, void* )
94 {
95 
96  // Since MORPH_X : 2,3,4,5 and 6
97  int operation = morph_operator + 2;
98 
99  Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
100 
102  morphologyEx( src, dst, operation, element );
103  imshow( window_name, dst );
104 }
105 
106 
void Morphology_Operations(int, void *)
int morph_operator
int const max_kernel_size
const char * window_name
Mat dst
int const max_operator
int morph_size
Mat src
Global variables.
int const max_elem
int main(int, char **argv)
int morph_elem


caltech_lanes
Author(s): Ricardo Morais
autogenerated on Mon Mar 2 2015 01:31:31