#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <string>
static void help()
{
printf("\nShow off image morphology: erosion, dialation, open and close\n"
"Call:\n morphology2 [image]\n"
"This program also shows use of rect, ellipse and cross kernels\n\n");
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"
"\tSPACE - loop through all the options\n" );
}
int max_iters = 10;
int open_close_pos = 0;
int erode_dilate_pos = 0;
static void OpenClose(int, void*)
{
int n = open_close_pos - max_iters;
int an = n > 0 ? n : -n;
if( n < 0 )
else
}
static void ErodeDilate(int, void*)
{
int n = erode_dilate_pos - max_iters;
int an = n > 0 ? n : -n;
if( n < 0 )
erode(src, dst, element);
else
}
int main( int argc, char** argv )
{
{
help();
return 0;
}
std::string filename = parser.
get<std::string>(
"@image");
{
help();
return -1;
}
open_close_pos = erode_dilate_pos = max_iters;
createTrackbar(
"iterations",
"Open/Close",&open_close_pos,max_iters*2+1,OpenClose);
createTrackbar(
"iterations",
"Erode/Dilate",&erode_dilate_pos,max_iters*2+1,ErodeDilate);
for(;;)
{
OpenClose(open_close_pos, 0);
ErodeDilate(erode_dilate_pos, 0);
if( c == 27 )
break;
if( c == 'e' )
else if( c == 'r' )
else if( c == 'c' )
else if( c == ' ' )
element_shape = (element_shape + 1) % 3;
}
return 0;
}