49 #include <visp3/core/vpDebug.h> 50 #include <visp3/core/vpImage.h> 51 #include <visp3/core/vpIoTools.h> 52 #include <visp3/gui/vpDisplayGDI.h> 53 #include <visp3/gui/vpDisplayGTK.h> 54 #include <visp3/gui/vpDisplayOpenCV.h> 55 #include <visp3/gui/vpDisplayX.h> 56 #include <visp3/io/vpImageIo.h> 57 #include <visp3/io/vpParseArgv.h> 58 #include <visp3/io/vpVideoReader.h> 60 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK) 63 #define GETOPTARGS "cdi:p:f:h" 65 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
66 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
79 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
82 Read an image sequence on the disk.\n\ 85 %s [-i <input images path>] [-p <personal image sequence path>]\n\ 91 -i <input images path> %s\n\ 92 Set ViSP-images input path.\n\ 93 From this path read \"cube/image.%%04d.pgm\"\n\ 95 Setting the VISP_INPUT_IMAGE_PATH environment\n\ 96 variable produces the same behaviour than using\n\ 99 -p <personal image sequence path> %s\n\ 100 Specify a personal folder containing an image sequence \n\ 102 Example : \"/Temp/ViSP-images/cube/image.%%04d.pgm\"\n\ 103 %%04d is for the image numbering.\n\ 105 -f <index of the first frame> \n\ 106 Specify the first image index.\n\ 109 Disable the mouse click. Useful to automaze the \n\ 110 execution of this program without humain intervention.\n\ 113 Turn off the display.\n\ 116 Print the help.\n\n", 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, std::string &ipath, std::string &ppath,
int &first,
bool &click_allowed,
146 click_allowed =
false;
158 first = atoi(optarg_);
161 usage(argv[0], NULL, ipath, ppath);
166 usage(argv[0], optarg_, ipath, ppath);
172 if ((c == 1) || (c == -1)) {
174 usage(argv[0], NULL, ipath, ppath);
175 std::cerr <<
"ERROR: " << std::endl;
176 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
183 int main(
int argc,
const char **argv)
186 std::string env_ipath;
187 std::string opt_ipath;
189 std::string opt_ppath;
190 std::string filename;
192 bool opt_click_allowed =
true;
193 bool opt_display =
true;
195 std::cout <<
"-------------------------------------------------------" << std::endl;
196 std::cout <<
" videoImageSequenceReader.cpp" << std::endl << std::endl;
198 std::cout <<
" reading an image sequence" << std::endl;
199 std::cout <<
"-------------------------------------------------------" << std::endl;
200 std::cout << std::endl;
207 if (!env_ipath.empty())
211 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_first, opt_click_allowed, opt_display) ==
false) {
216 if (!opt_ipath.empty())
221 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
222 if (ipath != env_ipath) {
223 std::cout << std::endl <<
"WARNING: " << std::endl;
224 std::cout <<
" Since -i <visp image path=" << ipath <<
"> " 225 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
226 <<
" we skip the environment variable." << std::endl;
231 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
232 usage(argv[0], NULL, ipath, opt_ppath);
233 std::cerr << std::endl <<
"ERROR:" << std::endl;
234 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
235 <<
" environment variable to specify the location of the " << std::endl
236 <<
" video path where test images are located." << std::endl
250 if (opt_ppath.empty()) {
253 filename.assign(opt_ppath);
260 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
263 #if defined VISP_HAVE_X11 265 #elif defined VISP_HAVE_GTK 267 #elif defined VISP_HAVE_GDI 269 #elif defined VISP_HAVE_OPENCV 275 display.
init(I, 100, 100,
"Display video frame");
280 if (opt_display && opt_click_allowed) {
281 std::cout <<
"Click in the image to read and display the second frame" << std::endl;
286 std::cout <<
"Current image number (should be " << opt_first + 1 <<
"): " << reader.
getFrameIndex() << std::endl;
293 if (opt_display && opt_click_allowed) {
294 std::cout <<
"Click on the image to read and display the last frame" << std::endl;
307 if (opt_display && opt_click_allowed) {
308 std::cout <<
"Click to see the video" << std::endl;
314 for (
int i = opt_first; i <= lastFrame; i++) {
316 std::cout <<
"Current image number: " << reader.
getFrameIndex() << std::endl;
323 if (opt_display && opt_click_allowed) {
324 std::cout <<
"Click to exit the test" << std::endl;
330 std::cout <<
"Catch an exception: " << e << std::endl;
337 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;
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)
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)
long getFrameIndex() const
void setFirstFrameIndex(const long first_frame)