From 0fc5ab84c0c375c1847733492ce73727dbc48f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Oberl=C3=A4nder?= Date: Thu, 15 May 2014 18:39:02 +0200 Subject: [PATCH 1/2] openni_pcd_recorder: Add command-line support for device IDs (like in openni_viewer). --- io/tools/openni_pcd_recorder.cpp | 111 +++++++++++++++++++++++++++---- 1 file changed, 98 insertions(+), 13 deletions(-) diff --git a/io/tools/openni_pcd_recorder.cpp b/io/tools/openni_pcd_recorder.cpp index 1ecac83d88f..e28cf0873ba 100644 --- a/io/tools/openni_pcd_recorder.cpp +++ b/io/tools/openni_pcd_recorder.cpp @@ -143,7 +143,7 @@ class PCDBuffer private: PCDBuffer (const PCDBuffer&); // Disabled copy constructor - PCDBuffer& operator =(const PCDBuffer&); // Disabled assignment operator + PCDBuffer& operator = (const PCDBuffer&); // Disabled assignment operator boost::mutex bmutex_; boost::condition_variable buff_empty_; @@ -336,23 +336,108 @@ ctrlC (int) } ////////////////////////////////////////////////////////////////////////////////////////// -int +void +printHelp (int default_buff_size, int, char **argv) +{ + using pcl::console::print_error; + using pcl::console::print_info; + + print_error ("Syntax is: %s (( | ) [-xyz] [-shift] [-buf X] | -l [] | -h | --help)]\n", argv [0]); + print_info ("%s -h | --help : shows this help\n", argv [0]); + print_info ("%s -xyz : save only XYZ data, even if the device is RGB capable\n", argv [0]); + print_info ("%s -shift : use OpenNI shift values rather than 12-bit depth\n", argv [0]); + print_info ("%s -buf X ; use a buffer size of X frames (default: ", argv [0]); + print_value ("%d", default_buff_size); print_info (")\n"); + print_info ("%s -l : list all available devices\n", argv [0]); + print_info ("%s -l :list all available modes for specified device\n", argv [0]); + print_info ("\t\t may be \"#1\", \"#2\", ... for the first, second etc device in the list\n"); +#ifndef _WIN32 + print_info ("\t\t bus@address for the device connected to a specific usb-bus / address combination\n"); + print_info ("\t\t \n"); +#endif + print_info ("\n\nexamples:\n"); + print_info ("%s \"#1\"\n", argv [0]); + print_info ("\t\t uses the first device.\n"); + print_info ("%s \"./temp/test.oni\"\n", argv [0]); + print_info ("\t\t uses the oni-player device to play back oni file given by path.\n"); + print_info ("%s -l\n", argv [0]); + print_info ("\t\t list all available devices.\n"); + print_info ("%s -l \"#2\"\n", argv [0]); + print_info ("\t\t list all available modes for the second device.\n"); + #ifndef _WIN32 + print_info ("%s A00361800903049A\n", argv [0]); + print_info ("\t\t uses the device with the serial number \'A00361800903049A\'.\n"); + print_info ("%s 1@16\n", argv [0]); + print_info ("\t\t uses the device on address 16 at USB bus 1.\n"); + #endif +} + +////////////////////////////////////////////////////////////////////////////////////////// +int main (int argc, char** argv) { print_highlight ("PCL OpenNI Recorder for saving buffered PCD (binary compressed to disk). See %s -h for options.\n", argv[0]); + std::string device_id (""); int buff_size = BUFFER_SIZE; - - if (find_switch (argc, argv, "-h") || find_switch (argc, argv, "--help")) + + if (argc >= 2) { - print_info ("Options are: \n" - " -xyz = save only XYZ data, even if the device is RGB capable\n" - " -shift = use OpenNI shift values rather than 12-bit depth\n" - " -buf X = use a buffer size of X frames (default: "); - print_value ("%d", buff_size); print_info (")\n"); - return (0); - } + device_id = argv[1]; + if (device_id == "--help" || device_id == "-h") + { + printHelp (buff_size, argc, argv); + return 0; + } + else if (device_id == "-l") + { + if (argc >= 3) + { + pcl::OpenNIGrabber grabber (argv[2]); + boost::shared_ptr device = grabber.getDevice (); + cout << "Supported depth modes for device: " << device->getVendorName () << " , " << device->getProductName () << endl; + std::vector > modes = grabber.getAvailableDepthModes (); + for (std::vector >::const_iterator it = modes.begin (); it != modes.end (); ++it) + { + cout << it->first << " = " << it->second.nXRes << " x " << it->second.nYRes << " @ " << it->second.nFPS << endl; + } + if (device->hasImageStream ()) + { + cout << endl << "Supported image modes for device: " << device->getVendorName () << " , " << device->getProductName () << endl; + modes = grabber.getAvailableImageModes (); + for (std::vector >::const_iterator it = modes.begin (); it != modes.end (); ++it) + { + cout << it->first << " = " << it->second.nXRes << " x " << it->second.nYRes << " @ " << it->second.nFPS << endl; + } + } + } + else + { + openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance (); + if (driver.getNumberDevices() > 0) + { + for (unsigned deviceIdx = 0; deviceIdx < driver.getNumberDevices (); ++deviceIdx) + { + cout << "Device: " << deviceIdx + 1 << ", vendor: " << driver.getVendorName (deviceIdx) << ", product: " << driver.getProductName (deviceIdx) + << ", connected: " << driver.getBus(deviceIdx) << " @ " << driver.getAddress (deviceIdx) << ", serial number: \'" << driver.getSerialNumber (deviceIdx) << "\'" << endl; + } + + } + else + cout << "No devices connected." << endl; + + cout <<"Virtual Devices available: ONI player" << endl; + } + return 0; + } + } + else + { + openni_wrapper::OpenNIDriver& driver = openni_wrapper::OpenNIDriver::getInstance (); + if (driver.getNumberDevices () > 0) + cout << "Device Id not set, using first device." << endl; + } bool just_xyz = find_switch (argc, argv, "-xyz"); openni_wrapper::OpenNIDevice::DepthMode depth_mode = openni_wrapper::OpenNIDevice::OpenNI_12_bit_depth; @@ -364,9 +449,9 @@ main (int argc, char** argv) else print_highlight ("Using default buffer size of %d frames.\n", buff_size); - print_highlight ("Starting the producer and consumer threads... Press Cltr+C to end\n"); + print_highlight ("Starting the producer and consumer threads... Press Ctrl+C to end\n"); - OpenNIGrabber grabber (""); + OpenNIGrabber grabber (device_id); if (grabber.providesCallback () && !just_xyz) { From 3d90a8df9b877b2e7ff808a0486079ad0dcd2d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Oberl=C3=A4nder?= Date: Thu, 15 May 2014 18:39:23 +0200 Subject: [PATCH 2/2] openni_pcd_recorder: Improve calculation of default buffer size. --- io/tools/openni_pcd_recorder.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/io/tools/openni_pcd_recorder.cpp b/io/tools/openni_pcd_recorder.cpp index e28cf0873ba..5edefb6cf0d 100644 --- a/io/tools/openni_pcd_recorder.cpp +++ b/io/tools/openni_pcd_recorder.cpp @@ -88,10 +88,10 @@ getTotalSystemMemory () return memory; } -const int BUFFER_SIZE = int (getTotalSystemMemory () / (640 * 480)); +const size_t BUFFER_SIZE = size_t (getTotalSystemMemory () / (640 * 480 * sizeof (pcl::PointXYZRGBA))); #else -const int BUFFER_SIZE = 200; +const size_t BUFFER_SIZE = 200; #endif //////////////////////////////////////////////////////////////////////////////////////////