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/vpDisplayFactory.h>
51 #include <visp3/io/vpImageIo.h>
52 #include <visp3/io/vpParseArgv.h>
53 #include <visp3/io/vpVideoReader.h>
55 #if defined(VISP_HAVE_DISPLAY)
58 #define GETOPTARGS "cdi:p:h"
60 #ifdef ENABLE_VISP_NAMESPACE
64 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath);
65 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
78 void usage(
const char *name,
const char *badparam, std::string ipath, std::string ppath)
81 Read a video file on the disk.\n\
84 %s [-i <input video path>] \n\
91 -i <input video path> %s\n\
92 Set video input path.\n\
93 From this path read \"video/cube.mpeg\"\n\
95 Setting the VISP_INPUT_IMAGE_PATH environment\n\
96 variable produces the same behaviour than using\n\
99 -p <personal video path> %s\n\
100 Specify a personal folder containing a video \n\
102 Example : \"/Temp/visp-images/video/video.mpeg\"\n\
105 Disable the mouse click. Useful to automate the \n\
106 execution of this program without human intervention.\n\
109 Turn off the display.\n\
112 Print the help.\n\n",
113 ipath.c_str(), ppath.c_str());
116 fprintf(stderr,
"ERROR: \n");
117 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
133 bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &display)
141 click_allowed =
false;
153 usage(argv[0],
nullptr, ipath, ppath);
158 usage(argv[0], optarg_, ipath, ppath);
164 if ((c == 1) || (c == -1)) {
166 usage(argv[0],
nullptr, ipath, ppath);
167 std::cerr <<
"ERROR: " << std::endl;
168 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
175 int main(
int argc,
const char **argv)
177 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
178 std::shared_ptr<vpDisplay> display;
183 std::string env_ipath;
184 std::string opt_ipath;
186 std::string opt_ppath;
187 std::string filename;
188 bool opt_click_allowed =
true;
189 bool opt_display =
true;
191 std::cout <<
"-------------------------------------------------------" << std::endl;
192 std::cout <<
" videoReader.cpp" << std::endl << std::endl;
194 std::cout <<
" reading a video file" << std::endl;
195 std::cout <<
"-------------------------------------------------------" << std::endl;
196 std::cout << std::endl;
203 if (!env_ipath.empty())
207 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, opt_display) ==
false) {
212 if (!opt_ipath.empty())
217 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
218 if (ipath != env_ipath) {
219 std::cout << std::endl <<
"WARNING: " << std::endl;
220 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
221 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
222 <<
" we skip the environment variable." << std::endl;
227 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
228 usage(argv[0],
nullptr, ipath, opt_ppath);
229 std::cerr << std::endl <<
"ERROR:" << std::endl;
230 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
231 <<
" environment variable to specify the location of the " << std::endl
232 <<
" video path where test images are located." << std::endl
246 if (opt_ppath.empty()) {
250 filename.assign(opt_ppath);
254 std::cout <<
"Process video in " << filename << std::endl;
260 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
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;
310 std::cout <<
"Catch an exception: " << e << std::endl;
312 #if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
313 if (display !=
nullptr) {
322 std::cout <<
"Sorry, no display is available. We quit this example." << std::endl;
Class that defines generic functionalities for display.
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
std::shared_ptr< vpDisplay > createDisplay()
Return a smart pointer vpDisplay specialization if a GUI library is available or nullptr otherwise.
vpDisplay * allocateDisplay()
Return a newly allocated vpDisplay specialization if a GUI library is available or nullptr otherwise.