#include <iostream>
static void help(char** argv)
{
cout << "\nThis program demonstrated the floodFill() function\n"
"Call:\n"
<< argv[0]
<< " [image_name -- Default: fruits.jpg]\n" << endl;
cout << "Hot keys: \n"
"\tESC - quit the program\n"
"\tc - switch color/grayscale mode\n"
"\tm - switch mask mode\n"
"\tr - restore the original image\n"
"\ts - use null-range floodfill\n"
"\tf - use gradient floodfill with fixed(absolute) range\n"
"\tg - use gradient floodfill with floating(relative) range\n"
"\t4 - use 4-connectivity mode\n"
"\t8 - use 8-connectivity mode\n" << endl;
}
Mat image0, image, gray,
mask;
int ffillMode = 1;
int loDiff = 20, upDiff = 20;
int connectivity = 4;
int isColor = true;
bool useMask = false;
int newMaskVal = 255;
static void onMouse( int event, int x, int y, int, void* )
{
return;
int lo = ffillMode == 0 ? 0 : loDiff;
int up = ffillMode == 0 ? 0 : upDiff;
int flags = connectivity + (newMaskVal << 8) +
int b = (unsigned)
theRNG() & 255;
int g = (unsigned)
theRNG() & 255;
int r = (unsigned)
theRNG() & 255;
Mat dst = isColor ? image : gray;
int area;
if( useMask )
{
}
else
{
}
cout << area << " pixels were repainted\n";
}
int main(
int argc,
char** argv )
{
"{help h | | show help message}{@image|fruits.jpg| input image}"
);
if (parser.has("help"))
{
parser.printMessage();
return 0;
}
string filename = parser.get<string>("@image");
if( image0.empty() )
{
cout << "Image empty\n";
parser.printMessage();
return 0;
}
help(argv);
image0.copyTo(image);
for(;;)
{
imshow(
"image", isColor ? image : gray);
if( c == 27 )
{
cout << "Exiting ...\n";
break;
}
switch( c )
{
case 'c':
if( isColor )
{
cout << "Grayscale mode is set\n";
isColor = false;
}
else
{
cout << "Color mode is set\n";
image0.copyTo(image);
isColor = true;
}
break;
case 'm':
if( useMask )
{
useMask = false;
}
else
{
useMask = true;
}
break;
case 'r':
cout << "Original image is restored\n";
image0.copyTo(image);
break;
case 's':
cout << "Simple floodfill mode is set\n";
ffillMode = 0;
break;
case 'f':
cout << "Fixed Range floodfill mode is set\n";
ffillMode = 1;
break;
case 'g':
cout << "Gradient (floating range) floodfill mode is set\n";
ffillMode = 2;
break;
case '4':
cout << "4-connectivity mode is set\n";
connectivity = 4;
break;
case '8':
cout << "8-connectivity mode is set\n";
connectivity = 8;
break;
}
}
return 0;
}
Designed for command line parsing.
Definition: utility.hpp:890
RNG & theRNG()
Returns the default random number generator.
Rect2i Rect
Definition: modules/core/include/opencv2/core/types.hpp:496
Point2i Point
Definition: modules/core/include/opencv2/core/types.hpp:209
Scalar_< double > Scalar
Definition: modules/core/include/opencv2/core/types.hpp:709
#define CV_8UC1
Definition: core/include/opencv2/core/hal/interface.h:88
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
GMat mask(const GMat &src, const GMat &mask)
Applies a mask to a matrix.
@ EVENT_LBUTTONDOWN
indicates that the left mouse button is pressed.
Definition: highgui.hpp:168
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
void destroyWindow(const String &winname)
Destroys the specified window.
void setMouseCallback(const String &winname, MouseCallback onMouse, void *userdata=0)
Sets mouse handler for the specified window.
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
Converts an image from one color space to another.
@ COLOR_BGR2GRAY
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc/include/opencv2/imgproc.hpp:555
int floodFill(InputOutputArray image, InputOutputArray mask, Point seedPoint, Scalar newVal, Rect *rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4)
Fills a connected component with the given color.
double threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type)
Applies a fixed-level threshold to each array element.
@ THRESH_BINARY
Definition: imgproc/include/opencv2/imgproc.hpp:325
@ FLOODFILL_FIXED_RANGE
Definition: imgproc/include/opencv2/imgproc.hpp:384
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107