36 #include <visp3/core/vpDisplay.h> 37 #include <visp3/core/vpImage.h> 38 #include <visp3/core/vpImageTools.h> 39 #include <visp3/core/vpIoTools.h> 40 #include <visp3/io/vpImageIo.h> 41 #include <visp3/io/vpParseArgv.h> 43 #include <visp3/gui/vpDisplayD3D.h> 44 #include <visp3/gui/vpDisplayGDI.h> 45 #include <visp3/gui/vpDisplayGTK.h> 46 #include <visp3/gui/vpDisplayOpenCV.h> 47 #include <visp3/gui/vpDisplayX.h> 55 #define GETOPTARGS "cdi:W:H:m:h" 69 void usage(
const char *name,
const char *badparam, std::string ipath,
unsigned int &w,
unsigned int &h,
int &m)
75 %s [-i <input image path>] [-W <width>] [-H <height>] [-m <method>] [-c] [-d]\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\ 90 Set the new image width.\n\ 93 Set the new image height.\n\ 96 Set resize interpolation method.\n\ 99 Disable mouse click.\n\ 102 Disable image display.\n\ 105 Print the help.\n\n", ipath.c_str(), w, h, m);
108 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
124 bool getOptions(
int argc,
const char **argv, std::string &ipath,
unsigned int &w,
unsigned int &h,
int &method,
125 bool &opt_display,
bool &opt_click)
136 w = (
unsigned int)atoi(optarg_);
139 h = (
unsigned int)atoi(optarg_);
142 method = atoi(optarg_);
145 usage(argv[0], NULL, ipath, w, h, method);
157 usage(argv[0], optarg_, ipath, w, h, method);
163 if ((c == 1) || (c == -1)) {
165 usage(argv[0], NULL, ipath, w, h, method);
166 std::cerr <<
"ERROR: " << std::endl;
167 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
175 int main(
int argc,
const char **argv)
178 std::string env_ipath;
179 std::string opt_ipath;
181 std::string filename;
182 unsigned int width = 101;
183 unsigned int height = 207;
185 bool opt_display =
true;
186 bool opt_click =
true;
193 if (!env_ipath.empty())
197 if (getOptions(argc, argv, opt_ipath, width, height, method, opt_display, opt_click) ==
false) {
202 if (!opt_ipath.empty())
207 if (opt_ipath.empty()) {
208 if (ipath != env_ipath) {
209 std::cout << std::endl <<
"WARNING: " << std::endl;
210 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 211 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
212 <<
" we skip the environment variable." << std::endl;
217 if (opt_ipath.empty() && env_ipath.empty()) {
218 usage(argv[0], NULL, ipath, width, height, method);
219 std::cerr << std::endl <<
"ERROR:" << std::endl;
220 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
221 <<
" environment variable to specify the location of the " << std::endl
222 <<
" image path where test images are located." << std::endl
230 for (
int m = 0; m < 3; m++) {
231 std::cout <<
"Interpolation method: " << m << std::endl;
234 for (
unsigned int cpt = 0; cpt < Itest.getSize(); cpt++) {
235 Itest.bitmap[cpt] = cpt;
238 Itest_resize2(Itest.getHeight(), Itest.getWidth());
241 std::cout <<
"Itest:\n" << Itest << std::endl;
242 std::cout <<
"Itest_resize:\n" << Itest_resize << std::endl;
243 std::cout <<
"Itest_resize2:\n" << Itest_resize2 << std::endl;
244 std::cout <<
"(Itest ==Itest_resize2)? " << (Itest == Itest_resize2) << std::endl;
247 for (
unsigned int cpt = 0; cpt < Itest.getSize(); cpt++) {
248 Itest.bitmap[cpt] = cpt;
254 std::cout <<
"\nItest:\n" << Itest << std::endl;
255 std::cout <<
"Itest_resize:\n" << Itest_resize << std::endl;
256 std::cout <<
"Itest_resize2:\n" << Itest_resize2 << std::endl;
257 std::cout <<
"(Itest ==Itest_resize2)? " << (Itest == Itest_resize2) << std::endl << std::endl;
265 std::cout <<
"Read image: " << filename << std::endl;
272 std::cout <<
"Time to resize from " << I.getWidth() <<
"x" << I.getHeight() <<
" to " << width <<
"x" << height
273 <<
": " << t <<
" ms" << std::endl;
275 #if defined(VISP_HAVE_X11) 277 #elif defined(VISP_HAVE_OPENCV) 279 #elif defined(VISP_HAVE_GTK) 281 #elif defined(VISP_HAVE_GDI) 283 #elif defined(VISP_HAVE_D3D9) 286 std::cerr <<
"No display available!" << std::endl;
291 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || \ 292 defined(VISP_HAVE_D3D9) 293 d1->
init(I, 0, 0,
"Grayscale image");
294 d2->
init(I_resize, (
int)I.
getWidth() + 80, 0,
"Grayscale image resized");
313 std::cout <<
"\nRead image: " << filename << std::endl;
320 std::cout <<
"Time to resize from " << I_color.
getWidth() <<
"x" << I_color.
getHeight() <<
" to " << width <<
"x" 321 << height <<
": " << t <<
" ms" << std::endl;
323 #if defined(VISP_HAVE_X11) 325 #elif defined(VISP_HAVE_OPENCV) 327 #elif defined(VISP_HAVE_GTK) 329 #elif defined(VISP_HAVE_GDI) 331 #elif defined(VISP_HAVE_D3D9) 334 std::cerr <<
"No display available!" << std::endl;
339 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || \ 340 defined(VISP_HAVE_D3D9) 341 d3->
init(I_color, 0, 0,
"Color image");
342 d4->
init(I_color_resize, (
int)I_color.
getWidth() + 80, 0,
"Color image resized");
355 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) || defined(VISP_HAVE_GDI) || \ 356 defined(VISP_HAVE_D3D9) 368 std::cout <<
"\n(I_color == I_color_double_half)? " << (I_color == I_color_double_half) << std::endl;
370 double root_mean_square_error = 0.0;
371 for (
unsigned int i = 0; i < I_color.getHeight(); i++) {
372 for (
unsigned int j = 0; j < I_color.getWidth(); j++) {
373 vpColVector c_error = I_color[i][j] - I_color_double_half[i][j];
374 root_mean_square_error += c_error.
sumSquare();
377 std::cout <<
"Root Mean Square Error: " << sqrt(root_mean_square_error / (I_color.getSize() * 3)) << std::endl;
384 std::cout <<
"\n(I_color == I_color_half_double)? " << (I_color == I_color_half_double) << std::endl;
386 root_mean_square_error = 0.0;
387 for (
unsigned int i = 0; i < I_color.getHeight(); i++) {
388 for (
unsigned int j = 0; j < I_color.getWidth(); j++) {
389 vpColVector c_error = I_color[i][j] - I_color_half_double[i][j];
390 root_mean_square_error += c_error.
sumSquare();
393 std::cout <<
"Root Mean Square Error: " << sqrt(root_mean_square_error / (I_color.getSize() * 3)) << std::endl;
397 std::cerr <<
"Catch an exception: " << e << std::endl;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getWidth() const
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
error that can be emited by ViSP classes.
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Display for windows using Direct3D 3rd party. Thus to enable this class Direct3D should be installed...
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
static void read(vpImage< unsigned char > &I, const std::string &filename)
Implementation of column vector and the associated operations.
unsigned int getHeight() const
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")