1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Add MORPH_DIAMOND support to samples and tutorials

This commit is contained in:
krikera
2025-06-27 21:09:53 +05:30
parent 5ee8919139
commit 27867cc72c
11 changed files with 42 additions and 16 deletions
+5 -2
View File
@@ -12,12 +12,13 @@ static void help(char** argv)
printf("\nShow off image morphology: erosion, dialation, open and close\n"
"Call:\n %s [image]\n"
"This program also shows use of rect, ellipse and cross kernels\n\n", argv[0]);
"This program also shows use of rect, ellipse, cross and diamond kernels\n\n", argv[0]);
printf( "Hot keys: \n"
"\tESC - quit the program\n"
"\tr - use rectangle structuring element\n"
"\te - use elliptic structuring element\n"
"\tc - use cross-shaped structuring element\n"
"\td - use diamond-shaped structuring element\n"
"\tSPACE - loop through all the options\n" );
}
@@ -101,8 +102,10 @@ int main( int argc, char** argv )
element_shape = MORPH_RECT;
else if( c == 'c' )
element_shape = MORPH_CROSS;
else if( c == 'd' )
element_shape = MORPH_DIAMOND;
else if( c == ' ' )
element_shape = (element_shape + 1) % 3;
element_shape = (element_shape + 1) % 4;
}
return 0;
@@ -18,7 +18,7 @@ int erosion_elem = 0;
int erosion_size = 0;
int dilation_elem = 0;
int dilation_size = 0;
int const max_elem = 2;
int const max_elem = 3;
int const max_kernel_size = 21;
/** Function Headers */
@@ -47,7 +47,7 @@ int main( int argc, char** argv )
moveWindow( "Dilation Demo", src.cols, 0 );
/// Create Erosion Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Erosion Demo",
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse \n 3: Diamond", "Erosion Demo",
&erosion_elem, max_elem,
Erosion );
@@ -56,7 +56,7 @@ int main( int argc, char** argv )
Erosion );
/// Create Dilation Trackbar
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "Dilation Demo",
createTrackbar( "Element:\n 0: Rect \n 1: Cross \n 2: Ellipse \n 3: Diamond", "Dilation Demo",
&dilation_elem, max_elem,
Dilation );
@@ -83,6 +83,7 @@ void Erosion( int, void* )
if( erosion_elem == 0 ){ erosion_type = MORPH_RECT; }
else if( erosion_elem == 1 ){ erosion_type = MORPH_CROSS; }
else if( erosion_elem == 2) { erosion_type = MORPH_ELLIPSE; }
else if( erosion_elem == 3) { erosion_type = MORPH_DIAMOND; }
//![kernel]
Mat element = getStructuringElement( erosion_type,
@@ -106,6 +107,7 @@ void Dilation( int, void* )
if( dilation_elem == 0 ){ dilation_type = MORPH_RECT; }
else if( dilation_elem == 1 ){ dilation_type = MORPH_CROSS; }
else if( dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
else if( dilation_elem == 3) { dilation_type = MORPH_DIAMOND; }
Mat element = getStructuringElement( dilation_type,
Size( 2*dilation_size + 1, 2*dilation_size+1 ),
@@ -18,7 +18,7 @@ int morph_elem = 0;
int morph_size = 0;
int morph_operator = 0;
int const max_operator = 4;
int const max_elem = 2;
int const max_elem = 3;
int const max_kernel_size = 21;
const char* window_name = "Morphology Transformations Demo";
@@ -54,7 +54,7 @@ int main( int argc, char** argv )
//![create_trackbar2]
/// Create Trackbar to select kernel type
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse", window_name,
createTrackbar( "Element:\n 0: Rect - 1: Cross - 2: Ellipse - 3: Diamond", window_name,
&morph_elem, max_elem,
Morphology_Operations );
//![create_trackbar2]