57 #include <visp3/core/vpConfig.h>
58 #include <visp3/core/vpDebug.h>
59 #include <visp3/core/vpDisplay.h>
60 #include <visp3/core/vpImage.h>
61 #include <visp3/core/vpImagePoint.h>
62 #include <visp3/io/vpImageIo.h>
63 #include <visp3/sensor/vpSickLDMRS.h>
64 #ifdef VISP_HAVE_MODULE_GUI
65 #include <visp3/gui/vpDisplayGTK.h>
66 #include <visp3/gui/vpDisplayX.h>
68 #include <visp3/core/vpIoTools.h>
69 #include <visp3/io/vpParseArgv.h>
70 #include <visp3/sensor/vp1394TwoGrabber.h>
72 #if (!defined(_WIN32) && (defined(__unix__) || defined(__unix) || (defined(__APPLE__) && defined(__MACH__)))) && \
73 (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK)) && defined(VISP_HAVE_THREADS)
78 #ifdef ENABLE_VISP_NAMESPACE
83 static int layerToDisplay = 0xF;
85 double time_offset = 0;
87 std::string output_path;
89 void laser_display_and_save_loop()
93 unsigned int width = map.getWidth();
94 unsigned int height = map.getHeight();
100 char filename[FILENAME_MAX];
101 std::ofstream fdscan;
104 for (
int layer = 0; layer < 4; layer++) {
122 #ifdef VISP_HAVE_MODULE_GUI
123 #if defined(VISP_HAVE_X11)
124 display =
new vpDisplayX;
125 #elif defined(VISP_HAVE_GTK)
128 display->init(map, 10, 10,
"Laser scan");
131 unsigned int iter = 0;
134 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK))
139 for (
int layer = 0; layer < 4; layer++) {
140 laserscan[layer] = shm_laserscan[layer];
145 for (
int layer = 0; layer < 4; layer++) {
146 if (!((0x1 << layer) & layerToDisplay)) {
147 std::cout <<
"Layer " << layer + 1 <<
" is not displayed" << std::endl;
151 std::vector<vpScanPoint> pointsLayer = laserscan[layer].
getScanPoints();
155 snprintf(filename, FILENAME_MAX,
"%s/scan%04u-layer%d.txt", output_path.c_str(), iter, layer + 1);
156 fdscan.open(filename);
159 fdscan <<
"# Scan layer [1 to 4] : " << layer + 1 << std::endl
160 <<
"# Start timestamp (s) : " << laserscan[layer].
getStartTimestamp() - time_offset << std::endl
161 <<
"# End timestamp (s) : " << laserscan[layer].
getEndTimestamp() - time_offset << std::endl
162 <<
"# Data : \"radial distance (m)\" \"horizontal angle "
163 "(rad)\" \"vertical angle (rad)\" \"X (m)\" \"Y (m)\" \"Z "
169 double resolution = 5;
171 for (
unsigned int i = 0; i < pointsLayer.size(); i++) {
176 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK))
181 fdscan << p << std::endl;
188 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK))
198 void laser_acq_loop()
200 std::string ip =
"131.254.12.119";
203 laser.setIpAddress(ip);
209 if (laser.measure(laserscan) ==
false)
213 for (
int layer = 0; layer < 4; layer++) {
214 shm_laserscan[layer] = laserscan[layer];
222 void camera_acq_and_display_loop()
224 #ifdef VISP_HAVE_DC1394
243 #ifdef VISP_HAVE_MODULE_GUI
244 #if defined(VISP_HAVE_X11)
245 display =
new vpDisplayX;
246 #elif defined(VISP_HAVE_GTK)
249 display->init(Q, 320, 10,
"Camera");
253 std::ofstream fdimage_ts;
255 std::string filename = output_path +
"/image_timestamp.txt";
256 fdimage_ts.open(filename.c_str());
257 fdimage_ts <<
"# [image name] [time stamp in second]" << std::endl;
260 char filename[FILENAME_MAX];
264 dc1394video_frame_t *frame = g.
dequeue(I, timestamp,
id);
266 double image_timestamp = timestamp / 1000000. - time_offset;
267 std::cout <<
"camera timestamp: " << image_timestamp <<
" s " << std::endl;
270 snprintf(filename, FILENAME_MAX,
"%s/image%04u.png", output_path.c_str(), iter);
272 fdimage_ts << filename <<
" " << image_timestamp << std::endl;
274 #if (defined(VISP_HAVE_X11) || defined(VISP_HAVE_GDI) || defined(VISP_HAVE_GTK))
292 int main(
int argc,
const char **argv)
295 output_path =
"data";
303 std::cout <<
"Cannot create " << output_path <<
" directory" << std::endl;
309 vpParseArgv::vpArgvInfo argTable[] = {
311 "The layer to display:\n"
312 "\t\t. 0x1 for layer 1.\n"
313 "\t\t. 0x2 for layer 2.\n"
314 "\t\t. 0x4 for layer 3.\n"
315 "\t\t. 0x8 for layer 4.\n"
316 "\t\tTo display all the layers you should set 0xF value."},
317 {
"-save",
vpParseArgv::ARGV_INT, (
char *)
nullptr, (
char *)&save,
"Turn to 1 in order to save data."},
319 "Display one or more measured layers form a Sick LD-MRS laser "
327 return (EXIT_FAILURE);
331 std::thread thread_camera_acq(&camera_acq_and_display_loop);
332 std::thread thread_laser_acq(&laser_acq_loop);
333 std::thread thread_laser_display(&laser_display_and_save_loop);
334 thread_camera_acq.join();
335 thread_laser_acq.join();
336 thread_laser_display.join();
341 std::cout <<
"Catch an exception: " << e << std::endl;
346 #elif !(defined(VISP_HAVE_X11) || defined(VISP_HAVE_GTK))
349 std::cout <<
"You do not have X11, or GTK functionalities to display images..." << std::endl;
350 std::cout <<
"Tip if you are on a unix-like system:" << std::endl;
351 std::cout <<
"- Install X11, configure again ViSP using cmake and build again this example" << std::endl;
352 std::cout <<
"Tip if you are on a windows-like system:" << std::endl;
353 std::cout <<
"- Install GTK, configure again ViSP using cmake and build again this example" << std::endl;
360 std::cout <<
"This example is only working on unix-like platforms \n"
361 <<
"since the Sick LD-MRS driver was not ported to Windows." << std::endl;
Class for firewire ieee1394 video devices using libdc1394-2.x api.
void acquire(vpImage< unsigned char > &I)
void enqueue(dc1394video_frame_t *frame)
dc1394video_frame_t * dequeue()
void getNumCameras(unsigned int &ncameras) const
Class to define RGB colors available for display functionalities.
static const vpColor blue
static const vpColor yellow
static const vpColor green
The vpDisplayGTK allows to display image using the GTK 3rd party library. Thus to enable this class G...
Class that defines generic functionalities for display.
static void display(const vpImage< unsigned char > &I)
static void displayLine(const vpImage< unsigned char > &I, const vpImagePoint &ip1, const vpImagePoint &ip2, const vpColor &color, unsigned int thickness=1, bool segment=true)
static void flush(const vpImage< unsigned char > &I)
error that can be emitted by ViSP classes.
static void write(const 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 ...
void quarterSizeImage(vpImage< Type > &res) const
Implements a laser scan data structure that contains especially the list of scanned points that have ...
double getStartTimestamp()
std::vector< vpScanPoint > getScanPoints()
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
@ ARGV_NO_DEFAULTS
No default options like -help.
@ ARGV_NO_LEFTOVERS
Print an error message if an option is not in the argument list.
@ ARGV_INT
Argument is associated to an int.
@ ARGV_END
End of the argument list.
@ ARGV_HELP
Argument is for help displaying.
Class that defines a single laser scanner point.
double getRadialDist() const
VISP_EXPORT double measureTimeSecond()
VISP_EXPORT double measureTimeMs()