50 #include <visp/vpDebug.h>
51 #include <visp/vpConfig.h>
53 #ifdef VISP_HAVE_OPENCV
55 #include <visp/vpImage.h>
56 #include <visp/vpImageIo.h>
57 #include <visp/vpDisplayOpenCV.h>
58 #include <visp/vpParseArgv.h>
59 #include <visp/vpIoTools.h>
61 #include <visp/vpTime.h>
73 #define GETOPTARGS "cdi:o:p:h"
86 void usage(
const char *name,
const char *badparam, std::string ipath,
87 std::string opath, std::string user)
90 Read an image on the disk, display it using OpenCV, display some\n\
91 features (line, circle, caracters) in overlay and finaly write \n\
92 the image and the overlayed features in an image on the disk.\n\
95 %s [-i <input image path>] [-o <output image path>]\n\
101 -i <input image path> %s\n\
102 Set image input path.\n\
103 From this path read \"ViSP-images/Klimt/Klimt.pgm\"\n\
105 Setting the VISP_INPUT_IMAGE_PATH environment\n\
106 variable produces the same behaviour than using\n\
109 -o <output image path> %s\n\
110 Set image output path.\n\
111 From this directory, creates the \"%s\"\n\
112 subdirectory depending on the username, where \n\
113 Klimt_grey.overlay.ppm output image is written.\n\
116 Disable the mouse click. Useful to automate the \n\
117 execution of this program without humain intervention.\n\
120 Disable the image display. This can be useful \n\
121 for automatic tests using crontab under Unix or \n\
122 using the task manager under Windows.\n\
125 Print the help.\n\n",
126 ipath.c_str(), opath.c_str(), user.c_str());
129 fprintf(stderr,
"ERROR: \n" );
130 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
153 bool getOptions(
int argc,
const char **argv,
154 std::string &ipath, std::string &opath,
bool &click_allowed,
155 std::string user,
bool &display)
162 case 'c': click_allowed =
false;
break;
163 case 'd': display =
false;
break;
164 case 'i': ipath = optarg;
break;
165 case 'o': opath = optarg;
break;
166 case 'h': usage(argv[0], NULL, ipath, opath, user);
return false;
break;
169 usage(argv[0], optarg, ipath, opath, user);
return false;
break;
173 if ((c == 1) || (c == -1)) {
175 usage(argv[0], NULL, ipath, opath, user);
176 std::cerr <<
"ERROR: " << std::endl;
177 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
185 main(
int argc,
const char ** argv)
187 std::string env_ipath;
188 std::string opt_ipath;
189 std::string opt_opath;
192 std::string filename;
193 std::string username;
194 bool opt_click_allowed =
true;
195 bool opt_display =
true;
198 char *ptenv = getenv(
"VISP_INPUT_IMAGE_PATH");
204 if (! env_ipath.empty())
211 opt_opath =
"C:\\temp";
218 if (getOptions(argc, argv, opt_ipath, opt_opath,
219 opt_click_allowed, username, opt_display) ==
false) {
224 if (!opt_ipath.empty())
226 if (!opt_opath.empty())
239 usage(argv[0], NULL, ipath, opath, username);
240 std::cerr << std::endl
241 <<
"ERROR:" << std::endl;
242 std::cerr <<
" Cannot create " << odirname << std::endl;
243 std::cerr <<
" Check your -o " << opath <<
" option " << std::endl;
250 if (!opt_ipath.empty() && !env_ipath.empty()) {
251 if (ipath != env_ipath) {
252 std::cout << std::endl
253 <<
"WARNING: " << std::endl;
254 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
255 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
256 <<
" we skip the environment variable." << std::endl;
261 if (opt_ipath.empty() && env_ipath.empty()){
262 usage(argv[0], NULL, ipath, opath, username);
263 std::cerr << std::endl
264 <<
"ERROR:" << std::endl;
265 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH "
267 <<
" environment variable to specify the location of the " << std::endl
268 <<
" image path where test images are located." << std::endl << std::endl;
291 display.
init(I, 100, 100,
"OpenCV display") ;
304 for (
unsigned i=0 ; i < I.
getHeight() ; i+=20) {
321 for (
unsigned i=0 ; i < I.
getWidth() ; i+=20) {
344 for (
unsigned int i=0 ; i < 100 ; i+=20) {
358 "ViSP is a marvelous software",
373 if (opt_click_allowed) {
374 std::cout <<
"\nA click to close the windows..." << std::endl;
401 displayRGBa.
init(Irgba, 100, 100,
"OpenCV color display");
409 if (opt_click_allowed) {
410 std::cout <<
"\nA click to display a cross..." << std::endl;
415 std::cout <<
"Cross position: " << ip << std::endl;
423 std::cout <<
"Cross position: " << ip << std::endl;
432 if (opt_click_allowed) {
433 std::cout <<
"\nA click to exit the program..." << std::endl;
435 std::cout <<
"Bye" << std::endl;
443 vpERROR_TRACE(
"You do not have OpenCV functionalities to display images...");