48 #include <visp3/core/vpImage.h> 49 #include <visp3/io/vpImageIo.h> 50 #include <visp3/io/vpParseArgv.h> 51 #include <visp3/core/vpIoTools.h> 52 #include <visp3/core/vpDebug.h> 53 #include <visp3/io/vpVideoReader.h> 54 #include <visp3/gui/vpDisplayOpenCV.h> 55 #include <visp3/gui/vpDisplayX.h> 56 #include <visp3/gui/vpDisplayGTK.h> 57 #include <visp3/gui/vpDisplayGDI.h> 59 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) 62 #define GETOPTARGS "cdi:p:f:h" 64 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
65 bool getOptions(
int argc,
const char **argv,
66 std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
bool &display);
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
81 Read an image sequence on the disk.\n\ 84 %s [-i <input images path>] [-p <personal image sequence path>]\n\ 90 -i <input images path> %s\n\ 91 Set ViSP-images input path.\n\ 92 From this path read \"ViSP-images/cube/image.%%04d.pgm\"\n\ 94 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 95 variable produces the same behaviour than using\n\ 98 -p <personal image sequence path> %s\n\ 99 Specify a personal folder containing an image sequence \n\ 101 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 102 %%04d is for the image numbering.\n\ 104 -f <index of the first frame> \n\ 105 Specify the first image index.\n\ 108 Disable the mouse click. Useful to automaze the \n\ 109 execution of this program without humain intervention.\n\ 112 Turn off the display.\n\ 115 Print the help.\n\n",
116 ipath.c_str(), ppath.c_str());
119 fprintf(stderr,
"ERROR: \n" );
120 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
137 bool getOptions(
int argc,
const char **argv,
138 std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
bool &display)
145 case 'c': click_allowed =
false;
break;
146 case 'd': display =
false;
break;
147 case 'i': ipath = optarg_;
break;
148 case 'p': ppath = optarg_;
break;
149 case 'f': first = atoi(optarg_);
break;
150 case 'h': usage(argv[0], NULL, ipath, ppath);
return false;
break;
153 usage(argv[0], optarg_, ipath, ppath);
return false;
break;
157 if ((c == 1) || (c == -1)) {
159 usage(argv[0], NULL, ipath, ppath);
160 std::cerr <<
"ERROR: " << std::endl;
161 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
171 main(
int argc,
const char ** argv)
174 std::string env_ipath;
175 std::string opt_ipath;
177 std::string opt_ppath;
178 std::string filename;
180 bool opt_click_allowed =
true;
181 bool opt_display =
true;
183 std::cout <<
"-------------------------------------------------------" << std::endl ;
184 std::cout <<
" videoImageSequenceReader.cpp" <<std::endl << std::endl ;
186 std::cout <<
" reading an image sequence" << std::endl ;
187 std::cout <<
"-------------------------------------------------------" << std::endl ;
188 std::cout << std::endl ;
194 if (! env_ipath.empty())
198 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed,
199 opt_display) ==
false) {
204 if (!opt_ipath.empty())
209 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
210 if (ipath != env_ipath) {
211 std::cout << std::endl
212 <<
"WARNING: " << std::endl;
213 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 214 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
215 <<
" we skip the environment variable." << std::endl;
220 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()){
221 usage(argv[0], NULL, ipath, opt_ppath);
222 std::cerr << std::endl
223 <<
"ERROR:" << std::endl;
224 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " 226 <<
" environment variable to specify the location of the " << std::endl
227 <<
" video path where test images are located." << std::endl << std::endl;
241 if (opt_ppath.empty())
247 filename.assign(opt_ppath);
256 #if defined VISP_HAVE_X11 258 #elif defined VISP_HAVE_GTK 260 #elif defined VISP_HAVE_GDI 262 #elif defined VISP_HAVE_OPENCV 268 display.
init(I, 100, 100,
"Display video frame") ;
273 if (opt_display && opt_click_allowed)
275 std::cout <<
"Click on the image to read and display the second frame" << std::endl;
287 if (opt_display && opt_click_allowed)
289 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
301 if (opt_display && opt_click_allowed)
303 std::cout <<
"Click to see the video" << std::endl;
309 for (
int i = opt_first; i <= lastFrame; i++)
319 if (opt_display && opt_click_allowed)
321 std::cout <<
"Click to exit the test" << std::endl;
328 std::cout <<
"Catch an exception: " << e << std::endl;
335 std::cout <<
"Sorry, no display is available. We quit this example." static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
error that can be emited by ViSP classes.
void init(vpImage< unsigned char > &I, int winx=-1, int winy=-1, const std::string &title="")
static void flush(const vpImage< unsigned char > &I)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
void open(vpImage< vpRGBa > &I)
bool getFrame(vpImage< vpRGBa > &I, long frame)
long getLastFrameIndex() const
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...
void setFileName(const char *filename)
void setFirstFrameIndex(const long first_frame)