40#include <visp3/core/vpImageTools.h>
41#include <visp3/core/vpIoTools.h>
42#include <visp3/imgproc/vpImgproc.h>
43#include <visp3/io/vpImageIo.h>
44#include <visp3/io/vpParseArgv.h>
47#define GETOPTARGS "cdi:o:h"
49#ifdef ENABLE_VISP_NAMESPACE
53void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
const std::string &user);
54bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
65void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
const std::string &user)
67#if defined(VISP_HAVE_DATASET)
68#if VISP_HAVE_DATASET_VERSION >= 0x030600
69 std::string ext(
"png");
71 std::string ext(
"pgm");
75 std::string ext(
"png");
78Test automatic thresholding.\n\
81 %s [-i <input image path>] [-o <output image path>]\n\
88 -i <input image path> %s\n\
89 Set image input path.\n\
90 From this path read \"calibration/grid36-03.%s\"\n\
92 Setting the VISP_INPUT_IMAGE_PATH environment\n\
93 variable produces the same behaviour than using\n\
96 -o <output image path> %s\n\
97 Set image output path.\n\
98 From this directory, creates the \"%s\"\n\
99 subdirectory depending on the username, where \n\
100 output result images are written.\n\
103 Print the help.\n\n",
104 ipath.c_str(), ext.c_str(), opath.c_str(), user.c_str());
107 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
121bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
135 usage(argv[0],
nullptr, ipath, opath, user);
143 usage(argv[0], optarg_, ipath, opath, user);
148 if ((c == 1) || (c == -1)) {
150 usage(argv[0],
nullptr, ipath, opath, user);
151 std::cerr <<
"ERROR: " << std::endl;
152 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
159int main(
int argc,
const char **argv)
162 std::string env_ipath;
163 std::string opt_ipath;
164 std::string opt_opath;
168 std::string username;
170#if defined(VISP_HAVE_DATASET)
171#if VISP_HAVE_DATASET_VERSION >= 0x030600
172 std::string ext(
"png");
174 std::string ext(
"pgm");
178 std::string ext(
"png");
186 if (!env_ipath.empty())
191 opt_opath =
"C:/temp";
200 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
205 if (!opt_ipath.empty())
207 if (!opt_opath.empty())
220 usage(argv[0],
nullptr, ipath, opt_opath, username);
221 std::cerr << std::endl <<
"ERROR:" << std::endl;
222 std::cerr <<
" Cannot create " << opath << std::endl;
223 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
230 if (!opt_ipath.empty() && !env_ipath.empty()) {
231 if (ipath != env_ipath) {
232 std::cout << std::endl <<
"WARNING: " << std::endl;
233 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
234 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
235 <<
" we skip the environment variable." << std::endl;
240 if (opt_ipath.empty() && env_ipath.empty()) {
241 usage(argv[0],
nullptr, ipath, opt_opath, username);
242 std::cerr << std::endl <<
"ERROR:" << std::endl;
243 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
244 <<
" environment variable to specify the location of the " << std::endl
245 <<
" image path where test images are located." << std::endl
257 std::cout <<
"Read: " <<
filename <<
" (" << I.getWidth() <<
"x" << I.getHeight() <<
")" << std::endl;
265 std::cout <<
"\nAutomatic thresholding (Huang): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
269 std::cout <<
"Write: " <<
filename << std::endl;
276 std::cout <<
"\nAutomatic thresholding (Intermodes): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
280 std::cout <<
"Write: " <<
filename << std::endl;
287 std::cout <<
"\nAutomatic thresholding (IsoData): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
291 std::cout <<
"Write: " <<
filename << std::endl;
298 std::cout <<
"\nAutomatic thresholding (Mean): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
302 std::cout <<
"Write: " <<
filename << std::endl;
309 std::cout <<
"\nAutomatic thresholding (Otsu): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
313 std::cout <<
"Write: " <<
filename << std::endl;
320 std::cout <<
"\nAutomatic thresholding (Triangle): " << threshold <<
" ; t=" <<
t <<
" ms" << std::endl;
324 std::cout <<
"Write: " <<
filename << std::endl;
329 std::cerr <<
"Catch an exception: " <<
e.what() << std::endl;
error that can be emitted by ViSP classes.
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition of the vpImage class member functions.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT unsigned char autoThreshold(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const vpAutoThresholdMethod &method, const unsigned char backgroundValue=0, const unsigned char foregroundValue=255)
@ AUTO_THRESHOLD_INTERMODES
@ AUTO_THRESHOLD_TRIANGLE
VISP_EXPORT double measureTimeMs()