46 #include <visp3/core/vpConfig.h>
47 #include <visp3/core/vpDebug.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpIoTools.h>
50 #include <visp3/gui/vpDisplayGDI.h>
51 #include <visp3/gui/vpDisplayGTK.h>
52 #include <visp3/gui/vpDisplayOpenCV.h>
53 #include <visp3/gui/vpDisplayX.h>
54 #include <visp3/io/vpImageIo.h>
55 #include <visp3/io/vpParseArgv.h>
56 #include <visp3/io/vpVideoReader.h>
58 #if defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_OPENCV) || defined(VISP_HAVE_GTK)
61 #define GETOPTARGS "cdi:p:h"
63 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
64 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
77 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
80 Read a video file on the disk.\n\
83 %s [-i <input video path>] \n\
90 -i <input video path> %s\n\
91 Set video input path.\n\
92 From this path read \"video/cube.mpeg\"\n\
94 Setting the VISP_INPUT_IMAGE_PATH environment\n\
95 variable produces the same behaviour than using\n\
98 -p <personal video path> %s\n\
99 Specify a personal folder containing a video \n\
101 Example : \"/Temp/visp-images/video/video.mpeg\"\n\
104 Disable the mouse click. Useful to automate the \n\
105 execution of this program without human intervention.\n\
108 Turn off the display.\n\
111 Print the help.\n\n",
112 ipath.c_str(), ppath.c_str());
115 fprintf(stderr,
"ERROR: \n");
116 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
132 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &display)
140 click_allowed =
false;
152 usage(argv[0],
nullptr, ipath, ppath);
157 usage(argv[0], optarg_, ipath, ppath);
163 if ((c == 1) || (c == -1)) {
165 usage(argv[0],
nullptr, ipath, ppath);
166 std::cerr <<
"ERROR: " << std::endl;
167 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
174 int main(
int argc,
const char **argv)
177 std::string env_ipath;
178 std::string opt_ipath;
180 std::string opt_ppath;
181 std::string filename;
182 bool opt_click_allowed =
true;
183 bool opt_display =
true;
185 std::cout <<
"-------------------------------------------------------" << std::endl;
186 std::cout <<
" videoReader.cpp" << std::endl << std::endl;
188 std::cout <<
" reading a video file" << std::endl;
189 std::cout <<
"-------------------------------------------------------" << std::endl;
190 std::cout << std::endl;
197 if (!env_ipath.empty())
201 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, opt_display) ==
false) {
206 if (!opt_ipath.empty())
211 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
212 if (ipath != env_ipath) {
213 std::cout << std::endl <<
"WARNING: " << std::endl;
214 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
215 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
216 <<
" we skip the environment variable." << std::endl;
221 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
222 usage(argv[0],
nullptr, ipath, opt_ppath);
223 std::cerr << std::endl <<
"ERROR:" << std::endl;
224 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
225 <<
" environment variable to specify the location of the " << std::endl
226 <<
" video path where test images are located." << std::endl
240 if (opt_ppath.empty()) {
243 filename.assign(opt_ppath);
247 std::cout <<
"Process video in " << filename << std::endl;
252 #if defined(VISP_HAVE_X11)
254 #elif defined(VISP_HAVE_GTK)
256 #elif defined(VISP_HAVE_GDI)
258 #elif defined(HAVE_OPENCV_HIGHGUI)
264 display.init(I, 100, 100,
"Display video frame");
283 if (opt_display && opt_click_allowed) {
284 std::cout <<
"Click to see the video" << std::endl;
288 while (!reader.
end()) {
290 std::cout <<
"Display frame: " << reader.
getFrameIndex() << std::endl;
293 if (opt_click_allowed) {
304 if (opt_display && opt_click_allowed) {
305 std::cout <<
"Click to exit this example" << std::endl;
309 std::cout <<
"Catch an exception: " << e << std::endl;
316 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emitted by ViSP classes.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to manipulate easily a video file or a sequence of images. As it inherits from the...
void acquire(vpImage< vpRGBa > &I)
void open(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
long getFrameIndex() const
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.