47#include <visp3/core/vpConfig.h>
48#if defined(VISP_HAVE_DISPLAY)
50#include <visp3/core/vpImage.h>
51#include <visp3/core/vpIoTools.h>
52#include <visp3/core/vpTime.h>
53#include <visp3/gui/vpDisplayFactory.h>
54#include <visp3/io/vpDiskGrabber.h>
55#include <visp3/io/vpParseArgv.h>
58#define GETOPTARGS "df:g:hi:l:s:z:"
60#ifdef ENABLE_VISP_NAMESPACE
77void usage(
const char *name,
const char *badparam, std::string ipath, std::string genericname,
long int first,
78 long int last,
long int step,
unsigned int nzero)
81Read a sequence of depth maps from the disk. Display it using X11, GDI,\n\
82GTK-2 or OpenCV. The sequence is made of separate depth maps.\n\
85 %s [-i <input image path>] \n\
86 [-f <first frame>] [-g <generic name>] [-l <last image> [-s <step>] \n\
87 [-z <number of zero>] [-d] [-h]\n", name);
91 -i <input image path> %s\n\
92 Set image input path. The sequence will be looked for in this folder.\n\
94 -g <generic name> %s\n\
95 Specify the generic name of the files.\n\
96 A generic name of file is for example myfile_%%04d.npy\n\
97 Supported formats ar: pfm, exr, npy or tiff.\n\
98 - pfm, exr and npy formats are supported natively\n\
99 - tiff format is only supported if ViSP is build with\n\
102 -f <first frame> %ld\n\
103 First frame number of the sequence.\n\
105 -l <last image> %ld\n\
106 Last frame number of the sequence.\n\
109 Step between two images.\n\
111 -z <number of zero> %u\n\
112 Number of digits to encode the image number.\n\
115 Turn off the display.\n\
118 Print the help.\n\n", ipath.c_str(), genericname.c_str(), first, last, step, nzero);
121 fprintf(stdout,
"\nERROR: Bad parameter [%s]\n", badparam);
139bool getOptions(
int argc,
const char **argv, std::string &ipath, std::string &genericname,
long &first,
140 long &last,
long &step,
unsigned int &nzero,
bool &display)
151 first = atol(optarg_);
154 genericname = optarg_;
160 last = std::atol(optarg_);
163 step = atol(optarg_);
166 nzero =
static_cast<unsigned int>(atoi(optarg_));
169 usage(argv[0],
nullptr, ipath, genericname, first, last, step, nzero);
173 usage(argv[0], optarg_, ipath, genericname, first, last, step, nzero);
178 if ((c == 1) || (c == -1)) {
180 usage(argv[0],
nullptr, ipath, genericname, first, last, step, nzero);
181 std::cerr <<
"ERROR: " << std::endl;
182 std::cerr <<
" Bad argument " << optarg_ << std::endl << std::endl;
200 float a = 255.f / (min - max);
201 float b = 255.f - a * min;
203#ifdef VISP_HAVE_OPENMP
204#pragma omp parallel for
206 for (
int i = 0;
i < size; ++
i) {
207 Idisp.bitmap[
i] =
static_cast<unsigned char>(a * Idepth.
bitmap[
i] + b);
223int main(
int argc,
const char **argv)
225#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
229 std::string env_ipath;
230 std::string opt_ipath;
232 std::string opt_genericname =
"mbt-depth/castel/castel/depth_image_%04d.pfm";
234 bool opt_display =
true;
236 long int opt_first = 0;
237 long int opt_last = 29;
238 long int opt_step = 1;
239 unsigned int opt_nzero = 4;
246 if (!env_ipath.empty())
250 if (getOptions(argc, argv, opt_ipath, opt_genericname, opt_first, opt_last, opt_step, opt_nzero,
251 opt_display) ==
false) {
256 if (!opt_ipath.empty()) {
260#if defined(VISP_HAVE_DATASET)
261#if VISP_HAVE_DATASET_VERSION < 0x030701
262 std::cout <<
"This example requires visp-images 3.7.1 or a more recent version..." << std::endl;
270 if (!opt_ipath.empty() && !env_ipath.empty()) {
271 if (ipath != env_ipath) {
272 std::cout << std::endl <<
"WARNING: " << std::endl;
273 std::cout <<
" Since -i <visp image path=" << ipath <<
"> "
274 <<
" is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
275 <<
" we skip the environment variable." << std::endl;
289 if (opt_genericname.empty()) {
293 if (!ipath.empty()) {
297 std::cout <<
"Sequence that will be read:= " << opt_genericname << std::endl;
309 Idisp.init(I.getHeight(), I.getWidth());
310 convertDepthImageToDisplayImage(I, Idisp);
311 std::cout <<
"Image size: width : " << I.getWidth() <<
" height: " << I.getHeight() << std::endl;
315#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
322 display->init(Idisp, 100, 100,
"Disk Framegrabber");
340 convertDepthImageToDisplayImage(I, Idisp);
349#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
350 if (display !=
nullptr) {
357 std::cout <<
"Catch an exception: " <<
e << std::endl;
358#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
359 if (display !=
nullptr) {
371 std::cout <<
"You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..."
373 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
374 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
375 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
376 std::cout <<
"- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
Class to grab (ie. read) images from the disk.
void open(vpImage< unsigned char > &I) VP_OVERRIDE
void acquire(vpImage< unsigned char > &I) VP_OVERRIDE
void setGenericName(const std::string &genericName)
void setImageNumber(long number)
void setNumberOfZero(unsigned int noz)
long getImageNumber() const
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
@ notInitialized
Used to indicate that a parameter is not initialized.
Definition of the vpImage class member functions.
unsigned int getWidth() const
unsigned int getSize() const
Type * bitmap
points toward the bitmap
unsigned int getHeight() const
void getMinMaxValue(Type &min, Type &max, bool onlyFiniteVal=true) const
Look for the minimum and the maximum value within the bitmap.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
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.
VISP_EXPORT double measureTimeMs()
VISP_EXPORT int wait(double t0, double t)