41 #include <visp3/core/vpImage.h> 42 #include <visp3/core/vpIoTools.h> 43 #include <visp3/core/vpMath.h> 44 #include <visp3/imgproc/vpImgproc.h> 45 #include <visp3/io/vpImageIo.h> 46 #include <visp3/io/vpParseArgv.h> 55 #define GETOPTARGS "cdi:o:h" 57 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user);
58 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
69 void usage(
const char *name,
const char *badparam, std::string ipath, std::string opath, std::string user)
72 Test imgproc functions.\n\ 75 %s [-i <input image path>] [-o <output image path>]\n\ 81 -i <input image path> %s\n\ 82 Set image input path.\n\ 83 From this path read \"Klimt/Klimt.pgm\"\n\ 85 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 86 variable produces the same behaviour than using\n\ 89 -o <output image path> %s\n\ 90 Set image output path.\n\ 91 From this directory, creates the \"%s\"\n\ 92 subdirectory depending on the username, where \n\ 93 Klimt_grey.pgm output image is written.\n\ 96 Print the help.\n\n", ipath.c_str(), opath.c_str(), user.c_str());
99 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
112 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
126 usage(argv[0], NULL, ipath, opath, user);
135 usage(argv[0], optarg_, ipath, opath, user);
141 if ((c == 1) || (c == -1)) {
143 usage(argv[0], NULL, ipath, opath, user);
144 std::cerr <<
"ERROR: " << std::endl;
145 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
152 int main(
int argc,
const char **argv)
155 std::string env_ipath;
156 std::string opt_ipath;
157 std::string opt_opath;
160 std::string filename;
161 std::string username;
168 if (!env_ipath.empty())
173 opt_opath =
"C:/temp";
182 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
187 if (!opt_ipath.empty())
189 if (!opt_opath.empty())
201 usage(argv[0], NULL, ipath, opt_opath, username);
202 std::cerr << std::endl <<
"ERROR:" << std::endl;
203 std::cerr <<
" Cannot create " << opath << std::endl;
204 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
211 if (!opt_ipath.empty() && !env_ipath.empty()) {
212 if (ipath != env_ipath) {
213 std::cout << std::endl <<
"WARNING: " << std::endl;
214 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 215 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
216 <<
" we skip the environment variable." << std::endl;
221 if (opt_ipath.empty() && env_ipath.empty()) {
222 usage(argv[0], NULL, ipath, opt_opath, username);
223 std::cerr << std::endl <<
"ERROR:" << std::endl;
224 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
225 <<
" environment variable to specify the location of the " << std::endl
226 <<
" image path where test images are located." << std::endl
242 std::cout <<
"Read image: " << filename << std::endl;
245 std::cout <<
"Image: " << I_color.
getWidth() <<
"x" << I_color.
getHeight() << std::endl;
248 double alpha = 1.5, beta = -10.0;
251 vp::adjust(I_color, I_color_adjust, alpha, beta);
253 std::cout <<
"Time to do color adjust: " << t <<
" ms" << std::endl;
264 std::cout <<
"Time to do color histogram equalization: " << t <<
" ms" << std::endl;
276 std::cout <<
"Time to do color gamma correction: " << t <<
" ms" << std::endl;
287 std::cout <<
"Time to do color retinex: " << t <<
" ms" << std::endl;
298 std::cout <<
"Time to do color contrast stretching: " << t <<
" ms" << std::endl;
309 std::cout <<
"Time to do color HSV contrast stretching: " << t <<
" ms" << std::endl;
320 std::cout <<
"Time to do color unsharp mask: " << t <<
" ms" << std::endl;
331 std::cout <<
"Time to do color CLAHE: " << t <<
" ms" << std::endl;
344 std::cout <<
"\nRead image: " << filename << std::endl;
355 std::cout <<
"Time to do grayscale adjust: " << t <<
" ms" << std::endl;
366 std::cout <<
"Time to do grayscale histogram equalization: " << t <<
" ms" << std::endl;
378 std::cout <<
"Time to do grayscale gamma correction: " << t <<
" ms" << std::endl;
389 std::cout <<
"Time to do grayscale contrast stretching: " << t <<
" ms" << std::endl;
400 std::cout <<
"Time to do grayscale unsharp mask: " << t <<
" ms" << std::endl;
411 std::cout <<
"Time to do grayscale CLAHE: " << t <<
" ms" << std::endl;
419 std::cerr <<
"Catch an exception: " << e.
what() << std::endl;
VISP_EXPORT void unsharpMask(vpImage< unsigned char > &I, const unsigned int size=7, const double weight=0.6)
unsigned int getWidth() const
VISP_EXPORT void adjust(vpImage< unsigned char > &I, const double alpha, const double beta)
error that can be emited by ViSP classes.
VISP_EXPORT void gammaCorrection(vpImage< unsigned char > &I, const double gamma)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT void stretchContrast(vpImage< unsigned char > &I)
static void write(const vpImage< unsigned char > &I, const std::string &filename)
const char * what() const
VISP_EXPORT void stretchContrastHSV(vpImage< vpRGBa > &I)
VISP_EXPORT void clahe(const vpImage< unsigned char > &I1, vpImage< unsigned char > &I2, const int blockRadius=150, const int bins=256, const float slope=3.0f, const bool fast=true)
void halfSizeImage(vpImage< Type > &res) const
static void read(vpImage< unsigned char > &I, const std::string &filename)
VISP_EXPORT void equalizeHistogram(vpImage< unsigned char > &I)
unsigned int getHeight() const
VISP_EXPORT void retinex(vpImage< vpRGBa > &I, const int scale=240, const int scaleDiv=3, const int level=RETINEX_UNIFORM, const double dynamic=1.2, const int kernelSize=-1)