42#include <visp3/core/vpImage.h>
43#include <visp3/core/vpIoTools.h>
44#include <visp3/core/vpMath.h>
45#include <visp3/imgproc/vpImgproc.h>
46#include <visp3/io/vpImageIo.h>
47#include <visp3/io/vpParseArgv.h>
50#define GETOPTARGS "cdi:o:h"
52#ifdef ENABLE_VISP_NAMESPACE
56void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
const std::string &user);
57bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user);
68void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &opath,
const std::string &user)
71Test imgproc functions.\n\
74 %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\
97 ipath.c_str(), opath.c_str(), user.c_str());
100 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
113bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &opath, std::string user)
127 usage(argv[0],
nullptr, ipath, opath, user);
135 usage(argv[0], optarg_, ipath, opath, user);
140 if ((c == 1) || (c == -1)) {
142 usage(argv[0],
nullptr, ipath, opath, user);
143 std::cerr <<
"ERROR: " << std::endl;
144 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
151int main(
int argc,
const char **argv)
154 std::string env_ipath;
155 std::string opt_ipath;
156 std::string opt_opath;
160 std::string username;
162#if defined(VISP_HAVE_DATASET)
163#if VISP_HAVE_DATASET_VERSION >= 0x030600
164 std::string ext(
"png");
166 std::string ext(
"pgm");
170 std::string ext(
"png");
178 if (!env_ipath.empty())
183 opt_opath =
"C:/temp";
192 if (getOptions(argc, argv, opt_ipath, opt_opath, username) ==
false) {
197 if (!opt_ipath.empty())
199 if (!opt_opath.empty())
212 usage(argv[0],
nullptr, ipath, opt_opath, username);
213 std::cerr << std::endl <<
"ERROR:" << std::endl;
214 std::cerr <<
" Cannot create " << opath << std::endl;
215 std::cerr <<
" Check your -o " << opt_opath <<
" option " << std::endl;
222 if (!opt_ipath.empty() && !env_ipath.empty()) {
223 if (ipath != env_ipath) {
224 std::cout << std::endl <<
"WARNING: " << std::endl;
225 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
226 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
227 <<
" we skip the environment variable." << std::endl;
232 if (opt_ipath.empty() && env_ipath.empty()) {
233 usage(argv[0],
nullptr, ipath, opt_opath, username);
234 std::cerr << std::endl <<
"ERROR:" << std::endl;
235 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
236 <<
" environment variable to specify the location of the " << std::endl
237 <<
" image path where test images are located." << std::endl
253 std::cout <<
"Read image: " <<
filename << std::endl;
256 std::cout <<
"Image: " << I_color.
getWidth() <<
"x" << I_color.
getHeight() << std::endl;
259 double alpha = 1.5, beta = -10.0;
264 std::cout <<
"Time to do color adjust: " <<
t <<
" ms" << std::endl;
275 std::cout <<
"Time to do color histogram equalization: " <<
t <<
" ms" << std::endl;
287 std::cout <<
"Time to do color gamma correction: " <<
t <<
" ms" << std::endl;
298 std::cout <<
"Time to do color retinex: " <<
t <<
" ms" << std::endl;
309 std::cout <<
"Time to do color contrast stretching: " <<
t <<
" ms" << std::endl;
320 std::cout <<
"Time to do color HSV contrast stretching: " <<
t <<
" ms" << std::endl;
328 const float sigma = 1.0f;
332 std::cout <<
"Time to do color unsharp mask: " <<
t <<
" ms" << std::endl;
343 std::cout <<
"Time to do color CLAHE: " <<
t <<
" ms" << std::endl;
356 std::cout <<
"\nRead image: " <<
filename << std::endl;
359 std::cout <<
"Image: " << I.getWidth() <<
"x" << I.getHeight() << std::endl;
367 std::cout <<
"Time to do grayscale adjust: " <<
t <<
" ms" << std::endl;
378 std::cout <<
"Time to do grayscale histogram equalization: " <<
t <<
" ms" << std::endl;
390 std::cout <<
"Time to do grayscale gamma correction: " <<
t <<
" ms" << std::endl;
401 std::cout <<
"Time to do grayscale contrast stretching: " <<
t <<
" ms" << std::endl;
412 std::cout <<
"Time to do grayscale unsharp mask: " <<
t <<
" ms" << std::endl;
423 std::cout <<
"Time to do grayscale CLAHE: " <<
t <<
" ms" << std::endl;
432 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.
void halfSizeImage(vpImage< Type > &res) const
unsigned int getWidth() const
unsigned int getHeight() const
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
VISP_EXPORT void adjust(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, double alpha, double beta)
VISP_EXPORT void clahe(const VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I1, VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I2, int blockRadius=150, int bins=256, float slope=3.0f, bool fast=true)
VISP_EXPORT void stretchContrast(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I)
VISP_EXPORT void stretchContrastHSV(VISP_NAMESPACE_ADDRESSING vpImage< VISP_NAMESPACE_ADDRESSING vpRGBa > &I)
VISP_EXPORT void gammaCorrection(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const float &gamma, const vpGammaMethod &method=GAMMA_MANUAL, const VISP_NAMESPACE_ADDRESSING vpImage< bool > *p_mask=nullptr)
VISP_EXPORT void equalizeHistogram(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, const VISP_NAMESPACE_ADDRESSING vpImage< bool > *p_mask=nullptr)
VISP_EXPORT void retinex(VISP_NAMESPACE_ADDRESSING vpImage< VISP_NAMESPACE_ADDRESSING vpRGBa > &I, int scale=240, int scaleDiv=3, int level=RETINEX_UNIFORM, double dynamic=1.2, int kernelSize=-1)
VISP_EXPORT void unsharpMask(VISP_NAMESPACE_ADDRESSING vpImage< unsigned char > &I, float sigma, double weight=0.6)
VISP_EXPORT double measureTimeMs()