41 #include <visp3/core/vpImageTools.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/imgproc/vpImgproc.h> 44 #include <visp3/io/vpImageIo.h> 45 #include <visp3/io/vpParseArgv.h> 54 #define GETOPTARGS "cdi:o:h" 56 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
57 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
68 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
71 Test flood fill algorithm.\n\ 74 %s [-i <input image path>] [-o <output image path>]\n\ 80 -i <input image path> %s\n\ 81 Set image input path.\n\ 82 From this path read \"Klimt/Klimt.pgm\"\n\ 84 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 85 variable produces the same behaviour than using\n\ 88 -o <output image path> %s\n\ 89 Set image output path.\n\ 90 From this directory, creates the \"%s\"\n\ 91 subdirectory depending on the username, where \n\ 92 output result images are written.\n\ 95 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
98 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
111 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
125 usage(argv[0], NULL, ipath, opath, user);
134 usage(argv[0], optarg_, ipath, opath, user);
140 if ((c == 1) || (c == -1)) {
142 usage(argv[0], NULL, ipath, opath, user);
143 std::cerr <<
"ERROR: " << std::endl;
144 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
153 std::cout <<
"\n" << name <<
":" << std::endl;
156 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
157 std::cout << std::setfill(
' ') << std::setw(2) << j <<
" ";
159 std::cout << std::endl;
161 std::cout << std::setfill(
' ') << std::setw(3) <<
"+";
162 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
163 std::cout << std::setw(3) <<
"---";
165 std::cout << std::endl;
167 for (
unsigned int i = 0; i < I.
getHeight(); i++) {
168 std::cout << std::setfill(
' ') << std::setw(2) << i <<
"|";
170 for (
unsigned int j = 0; j < I.
getWidth(); j++) {
171 std::cout << std::setfill(' ') << std::setw(2) << static_cast<unsigned int>(I[i][j]) <<
" ";
174 std::cout << std::endl;
178 int main(
int argc,
const char **argv)
181 std::string env_ipath;
182 std::string opt_ipath;
183 std::string opt_opath;
186 std::string filename;
187 std::string username;
194 if (!env_ipath.empty())
199 opt_opath =
"C:/temp";
208 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
213 if (!opt_ipath.empty())
215 if (!opt_opath.empty())
227 usage(argv[0], NULL, ipath, opt_opath, username);
228 std::cerr << std::endl <<
"ERROR:" << std::endl;
229 std::cerr <<
" Cannot create " << opath << std::endl;
230 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
237 if (!opt_ipath.empty() && !env_ipath.empty()) {
238 if (ipath != env_ipath) {
239 std::cout << std::endl <<
"WARNING: " << std::endl;
240 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 241 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
242 <<
" we skip the environment variable." << std::endl;
247 if (opt_ipath.empty() && env_ipath.empty()) {
248 usage(argv[0], NULL, ipath, opt_opath, username);
249 std::cerr << std::endl <<
"ERROR:" << std::endl;
250 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
251 <<
" environment variable to specify the location of the " << std::endl
252 <<
" image path where test images are located." << std::endl
261 unsigned char image_data[8 * 8] = {1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0,
262 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1,
263 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0};
266 printImage(I_test_flood_fill_4_connexity,
"Test image data");
268 unsigned char image_data_check_4_connexity[8 * 8] = {
269 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,
270 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0};
273 unsigned char image_data_check_8_connexity[8 * 8] = {
274 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0,
275 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0};
280 printImage(I_test_flood_fill_4_connexity,
"I_test_flood_fill_4_connexity");
282 if (I_test_flood_fill_4_connexity != I_check_4_connexity) {
285 std::cout <<
"\n(I_test_flood_fill_4_connexity == I_check_4_connexity)? " 286 << (I_test_flood_fill_4_connexity == I_check_4_connexity) << std::endl;
290 printImage(I_test_flood_fill_8_connexity,
"I_test_flood_fill_8_connexity");
292 if (I_test_flood_fill_8_connexity != I_check_8_connexity) {
295 std::cout <<
"\n(I_test_flood_fill_8_connexity == I_check_8_connexity)? " 296 << (I_test_flood_fill_8_connexity == I_check_8_connexity) << std::endl;
302 std::cout <<
"\nRead image: " << filename <<
" (" << I_klimt.
getWidth() <<
"x" << I_klimt.
getHeight() <<
")" 305 vpImageTools::binarise(I_klimt, (
unsigned char)127, (
unsigned char)255, (
unsigned char)0, (
unsigned char)255,
315 std::cout <<
"Flood fill on Klimt image (4-connexity): " << t <<
" ms" << std::endl;
324 std::cout <<
"Flood fill on Klimt image (8-connexity): " << t <<
" ms" << std::endl;
328 #if VISP_HAVE_OPENCV_VERSION >= 0x020408 329 cv::Mat matImg_klimt_4_connexity, matImg_klimt_8_connexity;
335 cv::floodFill(matImg_klimt_4_connexity, cv::Point(seed_x, seed_y), cv::Scalar(255), 0, cv::Scalar(), cv::Scalar(),
338 std::cout <<
"OpenCV flood fill on Klimt image (4-connexity): " << t <<
" ms" << std::endl;
348 cv::floodFill(matImg_klimt_8_connexity, cv::Point(seed_x, seed_y), cv::Scalar(255), 0, cv::Scalar(), cv::Scalar(),
351 std::cout <<
"OpenCV flood fill on Klimt image (8-connexity): " << t <<
" ms" << std::endl;
360 std::cout <<
"\n(I_klimt_flood_fill_4_connexity == " 361 "I_klimt_flood_fill_4_connexity_check)? " 362 << (I_klimt_flood_fill_4_connexity == I_klimt_flood_fill_4_connexity_check) << std::endl;
363 std::cout <<
"(I_klimt_flood_fill_8_connexity == " 364 "I_klimt_flood_fill_8_connexity_check)? " 365 << (I_klimt_flood_fill_8_connexity == I_klimt_flood_fill_8_connexity_check) << std::endl;
367 if (I_klimt_flood_fill_4_connexity != I_klimt_flood_fill_4_connexity_check) {
369 "I_klimt_flood_fill_4_connexity_check)");
371 if (I_klimt_flood_fill_8_connexity != I_klimt_flood_fill_8_connexity_check) {
373 "I_klimt_flood_fill_8_connexity_check)");
377 std::cout <<
"\nTest flood fill is ok!" << std::endl;
380 std::cerr <<
"Catch an exception: " << e.
what() << std::endl;
unsigned int getWidth() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
error that can be emited by ViSP classes.
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
const char * what() const
VISP_EXPORT void floodFill(vpImage< unsigned char > &I, const vpImagePoint &seedPoint, const unsigned char oldValue, const unsigned char newValue, const vpImageMorphology::vpConnexityType &connexity=vpImageMorphology::CONNEXITY_4)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...