@@ -21,72 +21,77 @@ void Dilation( int, void* );
21
21
/* * @function main */
22
22
int main ( int argc, char ** argv )
23
23
{
24
- // / Load an image
25
- src = cv::imread ( argv[1 ] );
26
-
27
- if ( !src.data )
28
- { return -1 ; }
29
-
30
- // / Create windows
31
- cv::namedWindow ( " Erosion Demo" , CV_WINDOW_AUTOSIZE );
32
- cv::namedWindow ( " Dilation Demo" , CV_WINDOW_AUTOSIZE );
33
- cvMoveWindow ( " Dilation Demo" , src.cols , 0 );
34
-
35
- // / Create Erosion Trackbar
36
- cv::createTrackbar ( " Element:\n 0: Rect \n 1: Cross \n 2: Ellipse" , " Erosion Demo" ,
37
- &erosion_elem, max_elem,
38
- Erosion );
39
-
40
- cv::createTrackbar ( " Kernel size:\n 2n +1" , " Erosion Demo" ,
41
- &erosion_size, max_kernel_size,
42
- Erosion );
43
-
44
- // / Create Dilation Trackbar
45
- cv::createTrackbar ( " Element:\n 0: Rect \n 1: Cross \n 2: Ellipse" , " Dilation Demo" ,
46
- &dilation_elem, max_elem,
47
- Dilation );
48
-
49
- cv::createTrackbar ( " Kernel size:\n 2n +1" , " Dilation Demo" ,
50
- &dilation_size, max_kernel_size,
51
- Dilation );
52
-
53
- // / Default start
54
- Erosion ( 0 , 0 );
55
- Dilation ( 0 , 0 );
56
-
57
- cv::waitKey (0 );
58
- return 0 ;
24
+ // / Load an image
25
+ src = cv::imread ( argv[1 ] );
26
+
27
+ if (!src.data )
28
+ return -1 ;
29
+ // / Create windows
30
+ cv::namedWindow ( " Erosion Demo" , CV_WINDOW_AUTOSIZE );
31
+ cv::namedWindow ( " Dilation Demo" , CV_WINDOW_AUTOSIZE );
32
+ cvMoveWindow ( " Dilation Demo" , src.cols , 0 );
33
+
34
+ // / Create Erosion Trackbar
35
+ cv::createTrackbar ( " Element:\n 0: Rect \n 1: Cross \n 2: Ellipse" , " Erosion Demo" ,
36
+ &erosion_elem, max_elem,
37
+ Erosion );
38
+
39
+ cv::createTrackbar ( " Kernel size:\n 2n +1" , " Erosion Demo" ,
40
+ &erosion_size, max_kernel_size,
41
+ Erosion );
42
+
43
+ // / Create Dilation Trackbar
44
+ cv::createTrackbar ( " Element:\n 0: Rect \n 1: Cross \n 2: Ellipse" , " Dilation Demo" ,
45
+ &dilation_elem, max_elem,
46
+ Dilation );
47
+
48
+ cv::createTrackbar ( " Kernel size:\n 2n +1" , " Dilation Demo" ,
49
+ &dilation_size, max_kernel_size,
50
+ Dilation );
51
+
52
+ // / Default start
53
+ Erosion ( 0 , 0 );
54
+ Dilation ( 0 , 0 );
55
+
56
+ cv::waitKey (0 );
57
+ return 0 ;
59
58
}
60
59
61
60
/* * @function Erosion */
62
61
void Erosion ( int , void * )
63
62
{
64
- int erosion_type;
65
- if ( erosion_elem == 0 ){ erosion_type = cv::MORPH_RECT; }
66
- else if ( erosion_elem == 1 ){ erosion_type = cv::MORPH_CROSS; }
67
- else if ( erosion_elem == 2 ) { erosion_type = cv::MORPH_ELLIPSE; }
68
-
69
- cv::Mat element = cv::getStructuringElement ( erosion_type,
70
- cv::Size ( 2 *erosion_size + 1 , 2 *erosion_size+1 ),
71
- cv::Point ( erosion_size, erosion_size ) );
72
-
73
- // / Apply the erosion operation
74
- cv::erode ( src, erosion_dst, element );
75
- cv::imshow ( " Erosion Demo" , erosion_dst );
63
+ int erosion_type;
64
+ if (erosion_elem == 0 )
65
+ erosion_type = cv::MORPH_RECT;
66
+ else if (erosion_elem == 1 )
67
+ erosion_type = cv::MORPH_CROSS;
68
+ else if (erosion_elem == 2 )
69
+ erosion_type = cv::MORPH_ELLIPSE;
70
+ cv::Mat element = cv::getStructuringElement ( erosion_type,
71
+ cv::Size ( 2 * erosion_size + 1 ,
72
+ 2 * erosion_size + 1 ),
73
+ cv::Point ( erosion_size, erosion_size ) );
74
+
75
+ // / Apply the erosion operation
76
+ cv::erode ( src, erosion_dst, element );
77
+ cv::imshow ( " Erosion Demo" , erosion_dst );
76
78
}
77
79
78
80
/* * @function Dilation */
79
81
void Dilation ( int , void * )
80
82
{
81
- int dilation_type;
82
- if ( dilation_elem == 0 ){ dilation_type = cv::MORPH_RECT; }
83
- else if ( dilation_elem == 1 ){ dilation_type = cv::MORPH_CROSS; }
84
- else if ( dilation_elem == 2 ) { dilation_type = cv::MORPH_ELLIPSE; }
85
-
86
- cv::Mat element = cv::getStructuringElement ( dilation_type,
87
- cv::Size ( 2 *dilation_size + 1 , 2 *dilation_size+1 ),
88
- cv::Point ( dilation_size, dilation_size ) );
89
- // / Apply the dilation operation
90
- cv::dilate ( src, dilation_dst, element );
91
- cv::imshow ( " Dilation Demo" , dilation_dst );
83
+ int dilation_type;
84
+ if (dilation_elem == 0 )
85
+ dilation_type = cv::MORPH_RECT;
86
+ else if (dilation_elem == 1 )
87
+ dilation_type = cv::MORPH_CROSS;
88
+ else if (dilation_elem == 2 )
89
+ dilation_type = cv::MORPH_ELLIPSE;
90
+ cv::Mat element = cv::getStructuringElement ( dilation_type,
91
+ cv::Size ( 2 * dilation_size + 1 ,
92
+ 2 * dilation_size + 1 ),
93
+ cv::Point ( dilation_size, dilation_size ) );
94
+ // / Apply the dilation operation
95
+ cv::dilate ( src, dilation_dst, element );
96
+ cv::imshow ( " Dilation Demo" , dilation_dst );
92
97
}
0 commit comments