41 #include <visp3/core/vpConfig.h>
43 #if defined(VISP_HAVE_THREADS) && (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI))
44 #include <condition_variable>
50 #include <visp3/core/vpImageConvert.h>
51 #include <visp3/core/vpIoException.h>
52 #include <visp3/core/vpIoTools.h>
53 #include <visp3/gui/vpDisplayGDI.h>
54 #include <visp3/gui/vpDisplayX.h>
55 #include <visp3/gui/vpDisplayPCL.h>
56 #include <visp3/io/vpImageIo.h>
57 #include <visp3/io/vpParseArgv.h>
58 #include <visp3/io/vpVideoWriter.h>
60 #if defined(VISP_HAVE_PCL)
61 #include <pcl/pcl_config.h>
62 #if defined(VISP_HAVE_PCL_COMMON)
63 #include <pcl/point_types.h>
64 #include <pcl/point_cloud.h>
66 #if defined(VISP_HAVE_PCL_IO)
67 #include <pcl/io/pcd_io.h>
71 #define GETOPTARGS "ci:bodh"
76 void usage(
const char *name,
const char *badparam)
78 std::cout <<
"\nNAME " << std::endl
80 <<
" - Read data acquired with a Realsense device." << std::endl
82 <<
"SYNOPSIS " << std::endl
84 <<
" [-i <directory>]"
91 std::cout <<
"\nOPTIONS " << std::endl
92 <<
" -i <directory>" << std::endl
93 <<
" Input folder that contains the data to read." << std::endl
96 <<
" Flag to display data in step by step mode triggered by a user click." << std::endl
99 <<
" Point cloud stream is saved in binary format." << std::endl
101 <<
" -o" << std::endl
102 <<
" Save color images in png format in a new folder." << std::endl
104 <<
" -d" << std::endl
105 <<
" Display depth in color." << std::endl
107 <<
" --help, -h" << std::endl
108 <<
" Display this helper message." << std::endl
112 std::cout <<
"\nERROR: Bad parameter " << badparam << std::endl;
116 bool getOptions(
int argc,
const char *argv[], std::string &input_directory,
bool &click,
bool &pointcloud_binary_format,
117 bool &save_video,
bool &color_depth)
120 const char **argv1 = (
const char **)argv;
126 input_directory = optarg;
132 pointcloud_binary_format =
true;
142 usage(argv[0],
nullptr);
147 usage(argv[0], optarg);
153 if ((c == 1) || (c == -1)) {
155 usage(argv[0],
nullptr);
156 std::cerr <<
"ERROR: " << std::endl;
157 std::cerr <<
" Bad argument " << optarg << std::endl << std::endl;
165 bool pointcloud_binary_format
166 #
if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
167 , pcl::PointCloud<pcl::PointXYZ>::Ptr point_cloud
171 char buffer[FILENAME_MAX];
172 std::stringstream ss;
173 ss << input_directory <<
"/color_image_%04d.jpg";
174 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), cpt);
175 std::string filename_color = buffer;
178 ss << input_directory <<
"/depth_image_%04d.bin";
179 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), cpt);
180 std::string filename_depth = buffer;
183 ss << input_directory <<
"/point_cloud_%04d" << (pointcloud_binary_format ?
".bin" :
".pcd");
184 snprintf(buffer, FILENAME_MAX, ss.str().c_str(), cpt);
185 std::string filename_pointcloud = buffer;
189 std::cerr <<
"End of sequence." << std::endl;
199 std::ifstream file_depth(filename_depth.c_str(), std::ios::in | std::ios::binary);
200 if (file_depth.is_open()) {
201 unsigned int height = 0, width = 0;
204 I_depth_raw.
resize(height, width);
206 uint16_t depth_value = 0;
207 for (
unsigned int i = 0; i < height; i++) {
208 for (
unsigned int j = 0; j < width; j++) {
210 I_depth_raw[i][j] = depth_value;
216 #if defined(VISP_HAVE_PCL)
217 if (pointcloud_binary_format) {
218 std::ifstream file_pointcloud(filename_pointcloud.c_str(), std::ios::in | std::ios::binary);
219 if (!file_pointcloud.is_open()) {
220 std::cerr <<
"Cannot read pointcloud file: " << filename_pointcloud << std::endl;
223 uint32_t height = 0, width = 0;
227 file_pointcloud.read((
char *)(&is_dense),
sizeof(is_dense));
229 point_cloud->width = width;
230 point_cloud->height = height;
231 point_cloud->is_dense = (is_dense != 0);
232 point_cloud->resize((
size_t)width * height);
234 float x = 0.0f, y = 0.0f, z = 0.0f;
235 for (uint32_t i = 0; i < height; i++) {
236 for (uint32_t j = 0; j < width; j++) {
241 point_cloud->points[(size_t)(i * width + j)].x = x;
242 point_cloud->points[(size_t)(i * width + j)].y = y;
243 point_cloud->points[(size_t)(i * width + j)].z = z;
248 #if defined(VISP_HAVE_PCL_IO)
249 if (pcl::io::loadPCDFile<pcl::PointXYZ>(filename_pointcloud, *point_cloud) == -1) {
250 std::cerr <<
"Cannot read PCD: " << filename_pointcloud << std::endl;
262 int main(
int argc,
const char *argv[])
264 std::string input_directory =
"";
266 bool pointcloud_binary_format =
false;
267 bool save_video =
false;
268 bool color_depth =
false;
271 if (!getOptions(argc, argv, input_directory, click, pointcloud_binary_format, save_video, color_depth)) {
284 bool init_display =
false;
286 #if defined(VISP_HAVE_PCL)
288 pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
289 #if defined(VISP_HAVE_PCL_VISUALIZATION)
290 vpDisplayPCL pcl_viewer;
299 writer.
setFileName(output_directory +
"/%04d.png");
307 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
309 std::lock_guard<std::mutex> lock(mutex);
310 quit = !readData(cpt_frame, input_directory, I_color, I_depth_raw, pointcloud_binary_format, pointcloud);
313 quit = !readData(cpt_frame, input_directory, I_color, I_depth_raw, pointcloud_binary_format);
322 d1.
init(I_color, 0, 0,
"Color image");
324 d2.
init(I_depth_color, I_color.
getWidth() + 10, 0,
"Depth image");
327 d2.
init(I_depth, I_color.
getWidth() + 10, 0,
"Depth image");
329 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION)
331 pcl_viewer.setWindowName(
"3D point cloud");
332 pcl_viewer.startThread(std::ref(mutex), pointcloud);
342 std::stringstream ss;
343 ss <<
"Frame: " << cpt_frame;
395 std::cerr <<
"Enable C++11 or higher (cmake -DUSE_CXX_STANDARD=11) and install X11 or GDI!" << std::endl;
Display for windows using GDI (available on any windows 32 platform).
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void init(vpImage< unsigned char > &I, int win_x=-1, int win_y=-1, const std::string &win_title="") vp_override
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)
static void createDepthHistogram(const vpImage< uint16_t > &src_depth, vpImage< vpRGBa > &dest_rgba)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
static void read(vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
unsigned int getWidth() const
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
void insert(const vpImage< Type > &src, const vpImagePoint &topLeft)
unsigned int getSize() const
unsigned int getHeight() const
Error that can be emitted by the vpIoTools class and its derivatives.
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Class that enables to write easily a video file or a sequence of images.
void saveFrame(vpImage< vpRGBa > &I)
void setFileName(const std::string &filename)
void open(vpImage< vpRGBa > &I)
VISP_EXPORT int wait(double t0, double t)
VISP_EXPORT std::string getDateTime(const std::string &format="%Y/%m/%d %H:%M:%S")
VISP_EXPORT double measureTimeMs()