The image sequence consists in successive depth maps. Several formats are supported, such as PFM, EXR if you have either TinyEXR or OpenCV, TIFF if you have OpenCV or NPY if you have MINIZ.
#include <stdlib.h>
#include <iostream>
#include <visp3/core/vpConfig.h>
#if defined(VISP_HAVE_DISPLAY)
#include <visp3/core/vpImage.h>
#include <visp3/core/vpIoTools.h>
#include <visp3/core/vpTime.h>
#include <visp3/gui/vpDisplayFactory.h>
#include <visp3/io/vpDiskGrabber.h>
#include <visp3/io/vpParseArgv.h>
#define GETOPTARGS "df:g:hi:l:s:z:"
#ifdef ENABLE_VISP_NAMESPACE
#endif
void usage(const char *name, const char *badparam, std::string ipath, std::string genericname, long int first,
long int last, long int step, unsigned int nzero)
{
fprintf(stdout, "\n\
Read a sequence of depth maps from the disk. Display it using X11, GDI,\n\
GTK-2 or OpenCV. The sequence is made of separate depth maps.\n\
\n\
SYNOPSIS\n\
%s [-i <input image path>] \n\
[-f <first frame>] [-g <generic name>] [-l <last image> [-s <step>] \n\
[-z <number of zero>] [-d] [-h]\n", name);
fprintf(stdout, "\n\
OPTIONS: Default\n\
-i <input image path> %s\n\
Set image input path. The sequence will be looked for in this folder.\n\
\n\
-g <generic name> %s\n\
Specify the generic name of the files.\n\
A generic name of file is for example myfile_%%04d.npy\n\
Supported formats ar: pfm, exr, npy or tiff.\n\
- pfm, exr and npy formats are supported natively\n\
- tiff format is only supported if ViSP is build with\n\
OpenCV support.\n\
\n\
-f <first frame> %ld\n\
First frame number of the sequence.\n\
\n\
-l <last image> %ld\n\
Last frame number of the sequence.\n\
\n\
-s <step> %ld\n\
Step between two images.\n\
\n\
-z <number of zero> %u\n\
Number of digits to encode the image number.\n\
\n\
-d \n\
Turn off the display.\n\
\n\
-h \n\
Print the help.\n\n", ipath.c_str(), genericname.c_str(), first, last, step, nzero);
if (badparam)
fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
}
bool getOptions(int argc, const char **argv, std::string &ipath, std::string &genericname, long &first,
long &last, long &step, unsigned int &nzero, bool &display)
{
const char *optarg_;
int c;
switch (c) {
case 'd':
display = false;
break;
case 'f':
first = atol(optarg_);
break;
case 'g':
genericname = optarg_;
break;
case 'i':
ipath = optarg_;
break;
case 'l':
last = std::atol(optarg_);
break;
case 's':
step = atol(optarg_);
break;
case 'z':
nzero = static_cast<unsigned int>(atoi(optarg_));
break;
case 'h':
usage(argv[0], nullptr, ipath, genericname, first, last, step, nzero);
return false;
default:
usage(argv[0], optarg_, ipath, genericname, first, last, step, nzero);
return false;
}
}
if ((c == 1) || (c == -1)) {
usage(argv[0], nullptr, ipath, genericname, first, last, step, nzero);
std::cerr << "ERROR: " << std::endl;
std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
return false;
}
return true;
}
{
float max, min;
float a = 255.f / (min - max);
float b = 255.f - a * min;
#ifdef VISP_HAVE_OPENMP
#pragma omp parallel for
#endif
for (
int i = 0;
i < size; ++
i) {
Idisp.bitmap[
i] =
static_cast<unsigned char>(a * Idepth.
bitmap[
i] + b);
}
}
int main(int argc, const char **argv)
{
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
#endif
try {
std::string env_ipath;
std::string opt_ipath;
std::string ipath;
std::string opt_genericname = "mbt-depth/castel/castel/depth_image_%04d.pfm";
bool opt_display = true;
long int opt_first = 0;
long int opt_last = 29;
long int opt_step = 1;
unsigned int opt_nzero = 4;
if (!env_ipath.empty())
ipath = env_ipath;
if (getOptions(argc, argv, opt_ipath, opt_genericname, opt_first, opt_last, opt_step, opt_nzero,
opt_display) == false) {
return EXIT_FAILURE;
}
if (!opt_ipath.empty()) {
ipath = opt_ipath;
}
else {
#if defined(VISP_HAVE_DATASET)
#if VISP_HAVE_DATASET_VERSION < 0x030701
std::cout << "This example requires visp-images 3.7.1 or a more recent version..." << std::endl;
return EXIT_SUCCESS;
#endif
#endif
}
if (!opt_ipath.empty() && !env_ipath.empty()) {
if (ipath != env_ipath) {
std::cout << std::endl << "WARNING: " << std::endl;
std::cout << " Since -i <visp image path=" << ipath << "> "
<< " is different from VISP_IMAGE_PATH=" << env_ipath << std::endl
<< " we skip the environment variable." << std::endl;
}
}
if (opt_genericname.empty()) {
}
else {
if (!ipath.empty()) {
}
std::cout << "Sequence that will be read:= " << opt_genericname << std::endl;
}
Idisp.init(I.getHeight(), I.getWidth());
convertDepthImageToDisplayImage(I, Idisp);
std::cout << "Image size: width : " << I.getWidth() << " height: " << I.getHeight() << std::endl;
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
#else
#endif
if (opt_display) {
display->init(Idisp, 100, 100, "Disk Framegrabber");
}
if (opt_display) {
convertDepthImageToDisplayImage(I, Idisp);
}
}
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
if (display != nullptr) {
delete display;
}
#endif
return EXIT_SUCCESS;
}
std::cout <<
"Catch an exception: " <<
e << std::endl;
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
if (display != nullptr) {
delete display;
}
#endif
return EXIT_FAILURE;
}
}
#else
int main()
{
std::cout << "You do not have X11, or GDI (Graphical Device Interface) functionalities to display images..."
<< std::endl;
std::cout << "Tip if you are on a unix-like system:" << std::endl;
std::cout << "- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
std::cout << "Tip if you are on a windows-like system:" << std::endl;
std::cout << "- Install GDI, configure again ViSP using cmake and build again this example" << std::endl;
return EXIT_SUCCESS;
}
#endif
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)