39 #include <visp3/core/vpImageTools.h> 40 #include <visp3/core/vpIoTools.h> 41 #include <visp3/imgproc/vpImgproc.h> 42 #include <visp3/io/vpImageIo.h> 43 #include <visp3/io/vpParseArgv.h> 52 #define GETOPTARGS "cdi:o:h" 54 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
55 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
66 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
69 Test automatic thresholding.\n\ 72 %s [-i <input image path>] [-o <output image path>]\n\ 78 -i <input image path> %s\n\ 79 Set image input path.\n\ 80 From this path read \"Klimt/Klimt.pgm\"\n\ 82 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 83 variable produces the same behaviour than using\n\ 86 -o <output image path> %s\n\ 87 Set image output path.\n\ 88 From this directory, creates the \"%s\"\n\ 89 subdirectory depending on the username, where \n\ 90 output result images are written.\n\ 93 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
96 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
110 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
124 usage(argv[0], NULL, ipath, opath, user);
133 usage(argv[0], optarg_, ipath, opath, user);
139 if ((c == 1) || (c == -1)) {
141 usage(argv[0], NULL, ipath, opath, user);
142 std::cerr <<
"ERROR: " << std::endl;
143 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
150 int main(
int argc,
const char **argv)
153 std::string env_ipath;
154 std::string opt_ipath;
155 std::string opt_opath;
158 std::string filename;
159 std::string username;
166 if (!env_ipath.empty())
171 opt_opath =
"C:/temp";
180 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
185 if (!opt_ipath.empty())
187 if (!opt_opath.empty())
199 usage(argv[0], NULL, ipath, opt_opath, username);
200 std::cerr << std::endl <<
"ERROR:" << std::endl;
201 std::cerr <<
" Cannot create " << opath << std::endl;
202 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
209 if (!opt_ipath.empty() && !env_ipath.empty()) {
210 if (ipath != env_ipath) {
211 std::cout << std::endl <<
"WARNING: " << std::endl;
212 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 213 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
214 <<
" we skip the environment variable." << std::endl;
219 if (opt_ipath.empty() && env_ipath.empty()) {
220 usage(argv[0], NULL, ipath, opt_opath, username);
221 std::cerr << std::endl <<
"ERROR:" << std::endl;
222 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
223 <<
" environment variable to specify the location of the " << std::endl
224 <<
" image path where test images are located." << std::endl
236 std::cout <<
"Read: " << filename <<
" (" << I.
getWidth() <<
"x" << I.
getHeight() <<
")" << std::endl;
244 std::cout <<
"\nAutomatic thresholding (Huang): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
248 std::cout <<
"Write: " << filename << std::endl;
255 std::cout <<
"\nAutomatic thresholding (Intermodes): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
259 std::cout <<
"Write: " << filename << std::endl;
266 std::cout <<
"\nAutomatic thresholding (IsoData): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
270 std::cout <<
"Write: " << filename << std::endl;
277 std::cout <<
"\nAutomatic thresholding (Mean): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
281 std::cout <<
"Write: " << filename << std::endl;
288 std::cout <<
"\nAutomatic thresholding (Otsu): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
292 std::cout <<
"Write: " << filename << std::endl;
299 std::cout <<
"\nAutomatic thresholding (Triangle): " << threshold <<
" ; t=" << t <<
" ms" << std::endl;
303 std::cout <<
"Write: " << filename << std::endl;
307 std::cerr <<
"Catch an exception: " << e.
what() << std::endl;
unsigned int getWidth() const
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 unsigned char autoThreshold(vpImage< unsigned char > &I, const vp::vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
static void read(vpImage< unsigned char > &I, const std::string &filename)
unsigned int getHeight() const