Skip to content

Commit

Permalink
DataRecorder tool: interface changed to use config file (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Dec 13, 2020
1 parent 3104dff commit d700d09
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 202 deletions.
2 changes: 1 addition & 1 deletion guilib/include/rtabmap/gui/PreferencesDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class RTABMAPGUI_EXP PreferencesDialog : public QDialog

virtual QString getIniFilePath() const;
virtual QString getTmpIniFilePath() const;
void init();
void init(const QString & iniFilePath = "");
void setCurrentPanelToSource();
virtual QString getDefaultWorkingDirectory() const;

Expand Down
4 changes: 2 additions & 2 deletions guilib/src/PreferencesDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ PreferencesDialog::~PreferencesDialog() {
delete _ui;
}

void PreferencesDialog::init()
void PreferencesDialog::init(const QString & iniFilePath)
{
UDEBUG("");
//First set all default values
Expand All @@ -1438,7 +1438,7 @@ void PreferencesDialog::init()
this->setParameter(iter->first, iter->second);
}

this->readSettings();
this->readSettings(iniFilePath);
this->writeSettings(getTmpIniFilePath());

_initialized = true;
Expand Down
262 changes: 63 additions & 199 deletions tools/DataRecorder/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <rtabmap/core/CameraRGBD.h>
#include <rtabmap/core/CameraStereo.h>
#include <rtabmap/core/Camera.h>
#include <rtabmap/core/DBReader.h>
#include <rtabmap/core/CameraThread.h>
#include <rtabmap/gui/DataRecorder.h>
#include <rtabmap/gui/PreferencesDialog.h>
#include <QApplication>
#include <signal.h>

Expand All @@ -42,27 +44,14 @@ using namespace rtabmap;
void showUsage()
{
printf("\nUsage:\n"
"dataRecorder [options] output.db\n"
"dataRecorder [options] config.ini output.db\n"
"Description:\n"
" A config file contains all camera parameters and driver used. That\n"
" file can be generated by RTAB-Map->Preferences->Save Settings(*.ini)\n"
" after modifying Source settings.\n"
"Options:\n"
" -hide Don't display the current cloud recorded.\n"
" -debug Set debug level for the logger.\n"
" -rate #.# Input rate Hz (default 0=inf)\n"
" -driver Driver number to use:\n"
" 0=OpenNI-PCL (Kinect)\n"
" 1=OpenNI2 (Kinect and Xtion PRO Live)\n"
" 2=Freenect (Kinect)\n"
" 3=OpenNI-CV (Kinect)\n"
" 4=OpenNI-CV-ASUS (Xtion PRO Live)\n"
" 5=Freenect2 (Kinect v2)\n"
" 6=DC1394 (Bumblebee2)\n"
" 7=FlyCapture2 (Bumblebee2)\n"
" 8=ZED stereo\n"
" 9=RealSense\n"
" 10=Kinect for Windows 2 SDK\n"
" 11=RealSense2\n"
" 12=Kinect for Azure SDK\n"
" 13=MYNT EYE S\n"
" -device "" Device ID (default \"\")\n");
" -debug Show debug log.\n"
" -hide Don't display the current cloud recorded.\n");
exit(1);
}

Expand All @@ -88,35 +77,16 @@ int main (int argc, char * argv[])
ULogger::setLevel(ULogger::kInfo);

// parse arguments
QString fileName;
std::string fileName;
bool show = true;
int driver = 0;
std::string deviceId;
float rate = 0.0f;
std::string configFile;

if(argc < 2)
if(argc < 3)
{
showUsage();
}
for(int i=1; i<argc-1; ++i)
for(int i=1; i<argc-2; ++i)
{
if(strcmp(argv[i], "-rate") == 0)
{
++i;
if(i < argc)
{
rate = uStr2Float(argv[i]);
if(rate < 0.0f)
{
showUsage();
}
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "-debug") == 0)
{
ULogger::setLevel(ULogger::kDebug);
Expand All @@ -127,192 +97,86 @@ int main (int argc, char * argv[])
show = false;
continue;
}
if(strcmp(argv[i], "-driver") == 0)
{
++i;
if(i < argc)
{
driver = std::atoi(argv[i]);
if(driver < 0 || driver > 13)
{
showUsage();
}
}
else
{
showUsage();
}
continue;
}
if(strcmp(argv[i], "-device") == 0)
{
++i;
if(i < argc)
{
deviceId = argv[i];
}
else
{
showUsage();
}
continue;
}

printf("Unrecognized option : %s\n", argv[i]);
showUsage();
}
configFile = argv[argc-2];
configFile = uReplaceChar(configFile, '~', UDirectory::homeDir());
fileName = argv[argc-1]; // the last is the output path
fileName = uReplaceChar(fileName, '~', UDirectory::homeDir());

if(UFile::getExtension(fileName.toStdString()).compare("db") != 0)
if(UFile::getExtension(fileName).compare("db") != 0)
{
printf("Database names must end with .db extension\n");
showUsage();
}

UINFO("Output = %s", fileName.toStdString().c_str());
UINFO("Output = %s", fileName.c_str());
UINFO("Show = %s", show?"true":"false");
UINFO("Rate =%f Hz", rate);
UINFO("Config = %s", configFile.c_str());

app = new QApplication(argc, argv);

PreferencesDialog dialog;
//Set working directory to default if not in config file to avoid message box
ParametersMap paramTmp;
Parameters::readINI(configFile, paramTmp);
if(paramTmp.find(Parameters::kRtabmapWorkingDirectory()) == paramTmp.end())
{
paramTmp.clear();
paramTmp.insert(ParametersPair(Parameters::kRtabmapWorkingDirectory(), dialog.getDefaultWorkingDirectory().toStdString()));
Parameters::writeINI(configFile, paramTmp);
}
dialog.init(configFile.c_str());

UINFO("Driver = %d", dialog.getSourceDriver());
UINFO("Rate = %f Hz", dialog.getGeneralInputRate());

// Catch ctrl-c to close the gui
// (Place this after QApplication's constructor)
signal(SIGABRT, &sighandler);
signal(SIGTERM, &sighandler);
signal(SIGINT, &sighandler);

rtabmap::Camera * camera = 0;
if(driver == 0)
{
camera = new rtabmap::CameraOpenni(deviceId, rate);
}
else if(driver == 1)
rtabmap::Camera * camera = dialog.createCamera();
if(camera == 0)
{
if(!rtabmap::CameraOpenNI2::available())
{
UERROR("Not built with OpenNI2 support...");
exit(-1);
}
camera = new rtabmap::CameraOpenNI2(deviceId, CameraOpenNI2::kTypeColorDepth, rate);
}
else if(driver == 2)
{
if(!rtabmap::CameraFreenect::available())
{
UERROR("Not built with Freenect support...");
exit(-1);
}
camera = new rtabmap::CameraFreenect(deviceId.size()?atoi(deviceId.c_str()):0, CameraFreenect::kTypeColorDepth, rate);
}
else if(driver == 3)
{
if(!rtabmap::CameraOpenNICV::available())
{
UERROR("Not built with OpenNI from OpenCV support...");
exit(-1);
}
camera = new rtabmap::CameraOpenNICV(false, rate);
}
else if(driver == 4)
{
if(!rtabmap::CameraOpenNICV::available())
{
UERROR("Not built with OpenNI from OpenCV support...");
exit(-1);
}
camera = new rtabmap::CameraOpenNICV(true, rate);
return -1;
}
else if(driver == 5)
ParametersMap parameters = dialog.getAllParameters();
cam = new CameraThread(camera, parameters);
cam->setMirroringEnabled(dialog.isSourceMirroring());
cam->setColorOnly(dialog.isSourceRGBDColorOnly());
cam->setImageDecimation(dialog.getSourceImageDecimation());
cam->setStereoToDepth(dialog.isSourceStereoDepthGenerated());
cam->setStereoExposureCompensation(dialog.isSourceStereoExposureCompensation());
cam->setScanParameters(
dialog.isSourceScanFromDepth(),
dialog.getSourceScanDownsampleStep(),
dialog.getSourceScanRangeMin(),
dialog.getSourceScanRangeMax(),
dialog.getSourceScanVoxelSize(),
dialog.getSourceScanNormalsK(),
dialog.getSourceScanNormalsRadius(),
(float)dialog.getSourceScanForceGroundNormalsUp());
if(dialog.getIMUFilteringStrategy()>0 && dynamic_cast<DBReader*>(camera) == 0)
{
if(!rtabmap::CameraFreenect2::available())
{
UERROR("Not built with Freenect2 support...");
exit(-1);
}
camera = new rtabmap::CameraFreenect2(deviceId.size()?atoi(deviceId.c_str()):0, rtabmap::CameraFreenect2::kTypeColor2DepthSD, rate);
cam->enableIMUFiltering(dialog.getIMUFilteringStrategy()-1, parameters);
}
else if(driver == 6)
if(dialog.isDepthFilteringAvailable())
{
if(!rtabmap::CameraStereoDC1394::available())
if(dialog.isBilateralFiltering())
{
UERROR("Not built with dc1394 support...");
exit(-1);
cam->enableBilateralFiltering(
dialog.getBilateralSigmaS(),
dialog.getBilateralSigmaR());
}
camera = new rtabmap::CameraStereoDC1394(rate);
}
else if(driver == 7)
{
if(!rtabmap::CameraStereoFlyCapture2::available())
{
UERROR("Not built with FlyCapture2/Triclops support...");
exit(-1);
}
camera = new rtabmap::CameraStereoFlyCapture2(rate);
}
else if(driver == 8)
{
if(!rtabmap::CameraStereoZed::available())
{
UERROR("Not built with ZED sdk support...");
exit(-1);
}
camera = new rtabmap::CameraStereoZed(uStr2Int(deviceId));
}
else if (driver == 9)
{
if (!rtabmap::CameraRealSense::available())
{
UERROR("Not built with RealSense support...");
exit(-1);
}
camera = new rtabmap::CameraRealSense(uStr2Int(deviceId));
}
else if (driver == 10)
{
if (!rtabmap::CameraK4W2::available())
{
UERROR("Not built with Kinect for Windows 2 SDK support...");
exit(-1);
}
camera = new rtabmap::CameraK4W2(uStr2Int(deviceId));
}
else if (driver == 11)
{
if (!rtabmap::CameraRealSense2::available())
{
UERROR("Not built with RealSense2 SDK support...");
exit(-1);
}
camera = new rtabmap::CameraRealSense2(deviceId);
}
else if (driver == 12)
{
if (!rtabmap::CameraK4A::available())
{
UERROR("Not built with Kinect for Azure SDK support...");
exit(-1);
}
camera = new rtabmap::CameraK4A(1);
}
else if (driver == 13)
{
if (!rtabmap::CameraMyntEye::available())
{
UERROR("Not built with Mynt Eye S support...");
exit(-1);
}
camera = new rtabmap::CameraMyntEye(deviceId);
}
else
{
UFATAL("Camera driver (%d) not found!", driver);
cam->setDistortionModel(dialog.getSourceDistortionModel().toStdString());
}
cam = new CameraThread(camera);
cam->enableIMUFiltering();

DataRecorder recorder;

if(recorder.init(fileName))
if(recorder.init(fileName.c_str()))
{
recorder.registerToEventsManager();
if(show)
Expand Down Expand Up @@ -341,7 +205,7 @@ int main (int argc, char * argv[])
}
else
{
UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.toStdString().c_str());
UERROR("Cannot initialize the recorder! Maybe the path is wrong: \"%s\"", fileName.c_str());
}

if(cam)
Expand Down

0 comments on commit d700d09

Please sign in to comment.