35 #include <visp3/core/vpImage.h>
36 #include <visp3/core/vpDisplay.h>
37 #include <visp3/io/vpImageIo.h>
38 #include <visp3/core/vpImageTools.h>
39 #include <visp3/core/vpIoTools.h>
40 #include <visp3/io/vpParseArgv.h>
42 #include <visp3/gui/vpDisplayOpenCV.h>
43 #include <visp3/gui/vpDisplayGTK.h>
44 #include <visp3/gui/vpDisplayX.h>
45 #include <visp3/gui/vpDisplayGDI.h>
46 #include <visp3/gui/vpDisplayD3D.h>
54 #define GETOPTARGS "cdi:W:H:m:h"
68 void usage(
const char *name,
const char *badparam, std::string ipath,
unsigned int &w,
unsigned int &h,
int &m)
74 %s [-i <input image path>] [-W <width>] [-H <height>] [-m <method>] [-c] [-d]\n\
80 -i <input image path> %s\n\
81 Set image input path.\n\
82 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
84 Setting the VISP_INPUT_IMAGE_PATH environment\n\
85 variable produces the same behaviour than using\n\
89 Set the new image width.\n\
92 Set the new image height.\n\
95 Set resize interpolation method.\n\
98 Disable mouse click.\n\
101 Disable image display.\n\
104 Print the help.\n\n",
105 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)
132 case 'i': ipath = optarg_;
break;
133 case 'W': w = (
unsigned int) atoi(optarg_);
break;
134 case 'H': h = (
unsigned int) atoi(optarg_);
break;
135 case 'm': method = atoi(optarg_);
break;
136 case 'h': usage(argv[0], NULL, ipath, w, h, method);
return false;
break;
138 case 'c': opt_click =
false;
break;
139 case 'd': opt_display =
false;
break;
143 usage(argv[0], optarg_, ipath, w, h, method);
return false;
break;
147 if ((c == 1) || (c == -1)) {
149 usage(argv[0], NULL, ipath, w, h, method);
150 std::cerr <<
"ERROR: " << std::endl;
151 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
160 main(
int argc,
const char ** argv)
163 std::string env_ipath;
164 std::string opt_ipath;
166 std::string filename;
167 unsigned int width = 101;
168 unsigned int height = 207;
170 bool opt_display =
true;
171 bool opt_click =
true;
177 if (! env_ipath.empty())
181 if (getOptions(argc, argv, opt_ipath, width, height, method, opt_display, opt_click) ==
false) {
186 if (!opt_ipath.empty())
191 if (opt_ipath.empty()) {
192 if (ipath != env_ipath) {
193 std::cout << std::endl
194 <<
"WARNING: " << std::endl;
195 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
196 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
197 <<
" we skip the environment variable." << std::endl;
202 if (opt_ipath.empty() && env_ipath.empty()){
203 usage(argv[0], NULL, ipath, width, height, method);
204 std::cerr << std::endl
205 <<
"ERROR:" << std::endl;
206 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
208 <<
" environment variable to specify the location of the " << std::endl
209 <<
" image path where test images are located." << std::endl << std::endl;
216 for (
int m = 0; m < 3; m++) {
217 std::cout <<
"Interpolation method: " << m << std::endl;
220 for (
unsigned int cpt = 0; cpt < Itest.getSize(); cpt++) {
221 Itest.bitmap[cpt] = cpt;
223 vpImage<unsigned char> Itest_resize(Itest.getHeight()*2, Itest.getWidth()*2), Itest_resize2(Itest.getHeight(), Itest.getWidth());
226 std::cout <<
"Itest:\n" << Itest << std::endl;
227 std::cout <<
"Itest_resize:\n" << Itest_resize << std::endl;
228 std::cout <<
"Itest_resize2:\n" << Itest_resize2 << std::endl;
229 std::cout <<
"(Itest ==Itest_resize2)? " << (Itest == Itest_resize2) << std::endl;
232 for (
unsigned int cpt = 0; cpt < Itest.getSize(); cpt++) {
233 Itest.bitmap[cpt] = cpt;
237 std::cout <<
"\nItest:\n" << Itest << std::endl;
238 std::cout <<
"Itest_resize:\n" << Itest_resize << std::endl;
239 std::cout <<
"Itest_resize2:\n" << Itest_resize2 << std::endl;
240 std::cout <<
"(Itest ==Itest_resize2)? " << (Itest == Itest_resize2) << std::endl << std::endl;
248 std::cout <<
"Read image: " << filename << std::endl;
255 std::cout <<
"Time to resize from " << I.
getWidth() <<
"x" << I.
getHeight() <<
" to " << width <<
"x" << height <<
": " << t <<
" ms" << std::endl;
257 #if defined (VISP_HAVE_X11)
259 #elif defined (VISP_HAVE_OPENCV)
261 #elif defined (VISP_HAVE_GTK)
263 #elif defined (VISP_HAVE_GDI)
265 #elif defined (VISP_HAVE_D3D9)
268 std::cerr <<
"No display available!" << std::endl;
273 #if defined (VISP_HAVE_X11) || defined (VISP_HAVE_OPENCV) || defined (VISP_HAVE_GTK) || defined (VISP_HAVE_GDI) || defined (VISP_HAVE_D3D9)
274 d1->
init(I, 0, 0,
"Grayscale image");
275 d2->
init(I_resize, (
int) I.
getWidth()+80, 0,
"Grayscale image resized");
295 std::cout <<
"\nRead image: " << filename << std::endl;
302 std::cout <<
"Time to resize from " << I_color.
getWidth() <<
"x" << I_color.
getHeight() <<
" to " << width <<
"x" << height <<
": " << t <<
" ms" << std::endl;
304 #if defined (VISP_HAVE_X11)
306 #elif defined (VISP_HAVE_OPENCV)
308 #elif defined (VISP_HAVE_GTK)
310 #elif defined (VISP_HAVE_GDI)
312 #elif defined (VISP_HAVE_D3D9)
315 std::cerr <<
"No display available!" << std::endl;
320 #if defined (VISP_HAVE_X11) || defined (VISP_HAVE_OPENCV) || defined (VISP_HAVE_GTK) || defined (VISP_HAVE_GDI) || defined (VISP_HAVE_D3D9)
321 d3->
init(I_color, 0, 0,
"Color image");
322 d4->
init(I_color_resize, (
int) I_color.
getWidth()+80, 0,
"Color image resized");
336 #if defined (VISP_HAVE_X11) || defined (VISP_HAVE_OPENCV) || defined (VISP_HAVE_GTK) || defined (VISP_HAVE_GDI) || defined (VISP_HAVE_D3D9)
347 std::cout <<
"\n(I_color == I_color_double_half)? " << (I_color == I_color_double_half) << std::endl;
349 double root_mean_square_error = 0.0;
350 for (
unsigned int i = 0; i < I_color.getHeight(); i++) {
351 for (
unsigned int j = 0; j < I_color.getWidth(); j++) {
352 vpColVector c_error = I_color[i][j] - I_color_double_half[i][j];
353 root_mean_square_error += c_error.
sumSquare();
356 std::cout <<
"Root Mean Square Error: " << sqrt(root_mean_square_error / (I_color.getSize()*3)) << std::endl;
361 std::cout <<
"\n(I_color == I_color_half_double)? " << (I_color == I_color_half_double) << std::endl;
363 root_mean_square_error = 0.0;
364 for (
unsigned int i = 0; i < I_color.getHeight(); i++) {
365 for (
unsigned int j = 0; j < I_color.getWidth(); j++) {
366 vpColVector c_error = I_color[i][j] - I_color_half_double[i][j];
367 root_mean_square_error += c_error.
sumSquare();
370 std::cout <<
"Root Mean Square Error: " << sqrt(root_mean_square_error / (I_color.getSize()*3)) << std::endl;
376 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="")