OpenNI2: depth shift can be negative. MainWindow: postProcessing() refactoring (split with and without dialog).

This commit is contained in:
matlabbe
2021-11-09 10:16:12 -05:00
parent 06150c697f
commit ec2aa5c952
4 changed files with 95 additions and 41 deletions

View File

@@ -178,8 +178,6 @@ void CameraOpenNI2::setOpenNI2StampsAndIDsUsed(bool used)
void CameraOpenNI2::setIRDepthShift(int horizontal, int vertical) void CameraOpenNI2::setIRDepthShift(int horizontal, int vertical)
{ {
#ifdef RTABMAP_OPENNI2 #ifdef RTABMAP_OPENNI2
UASSERT(horizontal >= 0);
UASSERT(vertical >= 0);
_depthHShift = horizontal; _depthHShift = horizontal;
_depthVShift = vertical; _depthVShift = vertical;
#endif #endif
@@ -538,10 +536,19 @@ SensorData CameraOpenNI2::captureImage(CameraInfo * info)
if(_type==kTypeColorDepth) if(_type==kTypeColorDepth)
{ {
if (_depthHShift > 0 || _depthVShift > 0) if (_depthHShift != 0 || _depthVShift != 0)
{ {
cv::Mat out = cv::Mat::zeros(depth.size(), depth.type()); cv::Mat out = cv::Mat::zeros(depth.size(), depth.type());
depth(cv::Rect(_depthHShift, _depthVShift, depth.cols - _depthHShift, depth.rows - _depthVShift)).copyTo(out(cv::Rect(0, 0, depth.cols - _depthHShift, depth.rows - _depthVShift))); depth(cv::Rect(
_depthHShift>0?_depthHShift:0,
_depthVShift>0?_depthVShift:0,
depth.cols - abs(_depthHShift),
depth.rows - abs(_depthVShift))).copyTo(
out(cv::Rect(
_depthHShift<0?-_depthHShift:0,
_depthVShift<0?-_depthVShift:0,
depth.cols - abs(_depthHShift),
depth.rows - abs(_depthVShift))));
depth = out; depth = out;
} }

View File

@@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/SensorData.h" #include "rtabmap/core/SensorData.h"
#include "rtabmap/core/OdometryEvent.h" #include "rtabmap/core/OdometryEvent.h"
#include "rtabmap/core/CameraInfo.h" #include "rtabmap/core/CameraInfo.h"
#include "rtabmap/core/Optimizer.h"
#include "rtabmap/gui/PreferencesDialog.h" #include "rtabmap/gui/PreferencesDialog.h"
#include <pcl/point_cloud.h> #include <pcl/point_cloud.h>
@@ -161,7 +162,7 @@ protected Q_SLOTS:
void exportPosesG2O(); void exportPosesG2O();
void exportImages(); void exportImages();
void exportOctomap(); void exportOctomap();
void postProcessing(); void showPostProcessingDialog();
void depthCalibration(); void depthCalibration();
void openWorkingDirectory(); void openWorkingDirectory();
void updateEditMenu(); void updateEditMenu();
@@ -312,6 +313,24 @@ protected:
double & odomSensorTimeOffset, double & odomSensorTimeOffset,
float & odomSensorScaleFactor); float & odomSensorScaleFactor);
void postProcessing(
bool refineNeighborLinks,
bool refineLoopClosureLinks,
// Detect more loop closures params:
bool detectMoreLoopClosures,
double clusterRadius,
double clusterAngle,
int iterations,
bool interSession,
bool intraSession,
// SBA params:
bool sba,
int sbaIterations,
double sbaVariance,
Optimizer::Type sbaType,
double sbaRematchFeatures,
bool abortIfDataMissing = true);
private: private:
Ui_mainWindow * _ui; Ui_mainWindow * _ui;

View File

@@ -102,7 +102,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "rtabmap/core/util3d_mapping.h" #include "rtabmap/core/util3d_mapping.h"
#include "rtabmap/core/util3d_surface.h" #include "rtabmap/core/util3d_surface.h"
#include "rtabmap/core/util3d_registration.h" #include "rtabmap/core/util3d_registration.h"
#include "rtabmap/core/Optimizer.h"
#include "rtabmap/core/optimizer/OptimizerCVSBA.h" #include "rtabmap/core/optimizer/OptimizerCVSBA.h"
#include "rtabmap/core/Graph.h" #include "rtabmap/core/Graph.h"
#include "rtabmap/core/RegistrationIcp.h" #include "rtabmap/core/RegistrationIcp.h"
@@ -394,7 +393,7 @@ MainWindow::MainWindow(PreferencesDialog * prefDialog, QWidget * parent, bool sh
connect(_ui->actionReset_Odometry, SIGNAL(triggered()), this, SLOT(resetOdometry())); connect(_ui->actionReset_Odometry, SIGNAL(triggered()), this, SLOT(resetOdometry()));
connect(_ui->actionTrigger_a_new_map, SIGNAL(triggered()), this, SLOT(triggerNewMap())); connect(_ui->actionTrigger_a_new_map, SIGNAL(triggered()), this, SLOT(triggerNewMap()));
connect(_ui->actionData_recorder, SIGNAL(triggered()), this, SLOT(dataRecorder())); connect(_ui->actionData_recorder, SIGNAL(triggered()), this, SLOT(dataRecorder()));
connect(_ui->actionPost_processing, SIGNAL(triggered()), this, SLOT(postProcessing())); connect(_ui->actionPost_processing, SIGNAL(triggered()), this, SLOT(showPostProcessingDialog()));
connect(_ui->actionDepth_Calibration, SIGNAL(triggered()), this, SLOT(depthCalibration())); connect(_ui->actionDepth_Calibration, SIGNAL(triggered()), this, SLOT(depthCalibration()));
_ui->actionPause->setShortcut(Qt::Key_Space); _ui->actionPause->setShortcut(Qt::Key_Space);
@@ -6043,7 +6042,44 @@ void MainWindow::exportPoses(int format)
} }
} }
void MainWindow::postProcessing() void MainWindow::showPostProcessingDialog()
{
if(_postProcessingDialog->exec() != QDialog::Accepted)
{
return;
}
postProcessing(
_postProcessingDialog->isRefineNeighborLinks(),
_postProcessingDialog->isRefineLoopClosureLinks(),
_postProcessingDialog->isDetectMoreLoopClosures(),
_postProcessingDialog->clusterRadius(),
_postProcessingDialog->clusterAngle(),
_postProcessingDialog->iterations(),
_postProcessingDialog->interSession(),
_postProcessingDialog->intraSession(),
_postProcessingDialog->isSBA(),
_postProcessingDialog->sbaIterations(),
_postProcessingDialog->sbaVariance(),
_postProcessingDialog->sbaType(),
_postProcessingDialog->sbaRematchFeatures());
}
void MainWindow::postProcessing(
bool refineNeighborLinks,
bool refineLoopClosureLinks,
bool detectMoreLoopClosures,
double clusterRadius,
double clusterAngle,
int iterations,
bool interSession,
bool intraSession,
bool sba,
int sbaIterations,
double sbaVariance,
Optimizer::Type sbaType,
double sbaRematchFeatures,
bool abortIfDataMissing)
{ {
if(_cachedSignatures.size() == 0) if(_cachedSignatures.size() == 0)
{ {
@@ -6054,22 +6090,6 @@ void MainWindow::postProcessing()
"refresh the cache.")); "refresh the cache."));
return; return;
} }
if(_postProcessingDialog->exec() != QDialog::Accepted)
{
return;
}
bool detectMoreLoopClosures = _postProcessingDialog->isDetectMoreLoopClosures();
bool refineNeighborLinks = _postProcessingDialog->isRefineNeighborLinks();
bool refineLoopClosureLinks = _postProcessingDialog->isRefineLoopClosureLinks();
double clusterRadius = _postProcessingDialog->clusterRadius();
double clusterAngle = _postProcessingDialog->clusterAngle();
int detectLoopClosureIterations = _postProcessingDialog->iterations();
bool sba = _postProcessingDialog->isSBA();
int sbaIterations = _postProcessingDialog->sbaIterations();
double sbaVariance = _postProcessingDialog->sbaVariance();
Optimizer::Type sbaType = _postProcessingDialog->sbaType();
double sbaRematchFeatures = _postProcessingDialog->sbaRematchFeatures();
if(!detectMoreLoopClosures && !refineNeighborLinks && !refineLoopClosureLinks && !sba) if(!detectMoreLoopClosures && !refineNeighborLinks && !refineLoopClosureLinks && !sba)
{ {
@@ -6104,10 +6124,14 @@ void MainWindow::postProcessing()
if(!allDataAvailable) if(!allDataAvailable)
{ {
QMessageBox::warning(this, tr("Not all data available in the GUI..."), QString msg = tr("Some data missing in the cache to respect the constraints chosen. "
tr("Some data missing in the cache to respect the constraints chosen. " "Try \"Edit->Download all clouds\" to update the cache and try again.");
"Try \"Edit->Download all clouds\" to update the cache and try again.")); UWARN(msg.toStdString().c_str());
return; if(abortIfDataMissing)
{
QMessageBox::warning(this, tr("Not all data available in the GUI..."), msg);
return;
}
} }
_progressDialog->resetProgress(); _progressDialog->resetProgress();
@@ -6159,13 +6183,11 @@ void MainWindow::postProcessing()
odomMaxInf = graph::getMaxOdomInf(_currentLinksMap); odomMaxInf = graph::getMaxOdomInf(_currentLinksMap);
} }
UASSERT(detectLoopClosureIterations>0); UASSERT(iterations>0);
bool interSession = _postProcessingDialog->interSession(); for(int n=0; n<iterations && !_progressCanceled; ++n)
bool intraSession = _postProcessingDialog->intraSession();
for(int n=0; n<detectLoopClosureIterations && !_progressCanceled; ++n)
{ {
_progressDialog->appendText(tr("Looking for more loop closures, clustering poses... (iteration=%1/%2, radius=%3 m angle=%4 degrees)") _progressDialog->appendText(tr("Looking for more loop closures, clustering poses... (iteration=%1/%2, radius=%3 m angle=%4 degrees)")
.arg(n+1).arg(detectLoopClosureIterations).arg(clusterRadius).arg(clusterAngle)); .arg(n+1).arg(iterations).arg(clusterRadius).arg(clusterAngle));
std::multimap<int, int> clusters = graph::radiusPosesClustering( std::multimap<int, int> clusters = graph::radiusPosesClustering(
std::map<int, Transform>(_currentPosesMap.upper_bound(0), _currentPosesMap.end()), std::map<int, Transform>(_currentPosesMap.upper_bound(0), _currentPosesMap.end()),
@@ -6411,13 +6433,13 @@ void MainWindow::postProcessing()
QApplication::processEvents(); QApplication::processEvents();
_progressDialog->incrementStep(); _progressDialog->incrementStep();
} }
_progressDialog->appendText(tr("Iteration %1/%2: Detected %3 loop closures!").arg(n+1).arg(detectLoopClosureIterations).arg(addedLinks.size()/2)); _progressDialog->appendText(tr("Iteration %1/%2: Detected %3 loop closures!").arg(n+1).arg(iterations).arg(addedLinks.size()/2));
if(addedLinks.size() == 0) if(addedLinks.size() == 0)
{ {
break; break;
} }
if(n+1 < detectLoopClosureIterations) if(n+1 < iterations)
{ {
_progressDialog->appendText(tr("Optimizing graph with new links (%1 nodes, %2 constraints)...") _progressDialog->appendText(tr("Optimizing graph with new links (%1 nodes, %2 constraints)...")
.arg(_currentPosesMap.size()).arg(_currentLinksMap.size())); .arg(_currentPosesMap.size()).arg(_currentLinksMap.size()));

View File

@@ -63,7 +63,7 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>-595</y>
<width>686</width> <width>686</width>
<height>3905</height> <height>3905</height>
</rect> </rect>
@@ -95,7 +95,7 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>15</number> <number>5</number>
</property> </property>
<widget class="QWidget" name="page_22"> <widget class="QWidget" name="page_22">
<layout class="QVBoxLayout" name="verticalLayout_29" stretch="0,1"> <layout class="QVBoxLayout" name="verticalLayout_29" stretch="0,1">
@@ -3413,7 +3413,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<item row="8" column="1"> <item row="8" column="1">
<widget class="QLabel" name="label_436"> <widget class="QLabel" name="label_436">
<property name="text"> <property name="text">
<string>IR-Depth vertical shift.</string> <string>IR-Depth vertical shift. Positive toward up, negative toward down.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@@ -3445,8 +3445,11 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<property name="suffix"> <property name="suffix">
<string> pix</string> <string> pix</string>
</property> </property>
<property name="minimum">
<number>-9999</number>
</property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>9999</number>
</property> </property>
</widget> </widget>
</item> </item>
@@ -3510,7 +3513,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<item row="7" column="1"> <item row="7" column="1">
<widget class="QLabel" name="label_435"> <widget class="QLabel" name="label_435">
<property name="text"> <property name="text">
<string>IR-Depth horizontal shift.</string> <string>IR-Depth horizontal shift. Positive toward left, negative toward right.</string>
</property> </property>
<property name="wordWrap"> <property name="wordWrap">
<bool>true</bool> <bool>true</bool>
@@ -3535,8 +3538,11 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<property name="suffix"> <property name="suffix">
<string> pix</string> <string> pix</string>
</property> </property>
<property name="minimum">
<number>-9999</number>
</property>
<property name="maximum"> <property name="maximum">
<number>65535</number> <number>9999</number>
</property> </property>
</widget> </widget>
</item> </item>