44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpDebug.h>
46#include <visp3/core/vpImage.h>
47#include <visp3/core/vpIoTools.h>
48#include <visp3/gui/vpDisplayFactory.h>
49#include <visp3/io/vpImageIo.h>
50#include <visp3/io/vpParseArgv.h>
51#include <visp3/io/vpVideoReader.h>
53#if defined(VISP_HAVE_DISPLAY)
56#define GETOPTARGS "cdi:p:h"
58#ifdef ENABLE_VISP_NAMESPACE
62void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath);
63bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
76void usage(
const char *name,
const char *badparam,
const std::string &ipath,
const std::string &ppath)
79Read a video file on the disk.\n\
82 %s [-i <input video path>] \n\
89 -i <input video path> %s\n\
90 Set video input path.\n\
91 From this path read \"video/cube.mpeg\"\n\
93 Setting the VISP_INPUT_IMAGE_PATH environment\n\
94 variable produces the same behaviour than using\n\
97 -p <personal video path> %s\n\
98 Specify a personal folder containing a video \n\
100 Example : \"/Temp/visp-images/video/video.mpeg\"\n\
103 Disable the mouse click. Useful to automate the \n\
104 execution of this program without human intervention.\n\
107 Turn off the display.\n\
110 Print the help.\n\n",
111 ipath.c_str(), ppath.c_str());
114 fprintf(stderr,
"ERROR: \n");
115 fprintf(stderr,
"\nBad parameter [%s]\n", badparam);
131bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &ppath,
bool &click_allowed,
bool &display)
139 click_allowed =
false;
151 usage(argv[0],
nullptr, ipath, ppath);
155 usage(argv[0], optarg_, ipath, ppath);
160 if ((c == 1) || (c == -1)) {
162 usage(argv[0],
nullptr, ipath, ppath);
163 std::cerr <<
"ERROR: " << std::endl;
164 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
171int main(
int argc,
const char **argv)
173#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
174 std::shared_ptr<vpDisplay> display;
179 std::string env_ipath;
180 std::string opt_ipath;
182 std::string opt_ppath;
184 bool opt_click_allowed =
true;
185 bool opt_display =
true;
187 std::cout <<
"-------------------------------------------------------" << std::endl;
188 std::cout <<
" videoReader.cpp" << std::endl << std::endl;
190 std::cout <<
" reading a video file" << std::endl;
191 std::cout <<
"-------------------------------------------------------" << std::endl;
192 std::cout << std::endl;
199 if (!env_ipath.empty())
203 if (getOptions(argc, argv, opt_ipath, opt_ppath, opt_click_allowed, opt_display) ==
false) {
208 if (!opt_ipath.empty())
213 if (!opt_ipath.empty() && !env_ipath.empty() && opt_ppath.empty()) {
214 if (ipath != env_ipath) {
215 std::cout << std::endl <<
"WARNING: " << std::endl;
216 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
217 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
218 <<
" we skip the environment variable." << std::endl;
223 if (opt_ipath.empty() && env_ipath.empty() && opt_ppath.empty()) {
224 usage(argv[0],
nullptr, ipath, opt_ppath);
225 std::cerr << std::endl <<
"ERROR:" << std::endl;
226 std::cerr <<
" Use -i <visp image path> option or set VISP_INPUT_IMAGE_PATH " << std::endl
227 <<
" environment variable to specify the location of the " << std::endl
228 <<
" video path where test images are located." << std::endl
242#if defined(VISP_HAVE_DATASET)
243#if VISP_HAVE_DATASET_VERSION >= 0x030702
244 std::string video(
"video/cube.mp4");
246 std::string video(
"video/cube.mpeg");
250 std::string video(
"video/cube.mp4");
253 if (opt_ppath.empty()) {
261 std::cout <<
"Process video in " <<
filename << std::endl;
267#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
290 if (opt_display && opt_click_allowed) {
291 std::cout <<
"Click to see the video" << std::endl;
295 while (!reader.
end()) {
297 std::cout <<
"Display frame: " << reader.
getFrameIndex() << std::endl;
300 if (opt_click_allowed) {
311 if (opt_display && opt_click_allowed) {
312 std::cout <<
"Click to exit this example" << std::endl;
317 std::cout <<
"Catch an exception: " <<
e << std::endl;
319#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
320 if (display !=
nullptr) {
329 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.
Definition of the vpImage class member functions.
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 open(vpImage< vpRGBa > &I) VP_OVERRIDE
void setFileName(const std::string &filename)
long getFrameIndex() const
void acquire(vpImage< vpRGBa > &I) VP_OVERRIDE
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.