RealSense: added depthScaledToRGBSize option to be able to feed ORB_SLAM2 with depth and RGB images with same size #287.

This commit is contained in:
matlabbe
2018-06-19 13:53:03 -04:00
parent c91431410e
commit 973bf93c77
5 changed files with 41 additions and 8 deletions

View File

@@ -386,6 +386,7 @@ public:
const Transform & localTransform = Transform::getIdentity()); const Transform & localTransform = Transform::getIdentity());
virtual ~CameraRealSense(); virtual ~CameraRealSense();
void setDepthScaledToRGBSize(bool enabled) {depthScaledToRGBSize_ = enabled;}
virtual bool init(const std::string & calibrationFolder = ".", const std::string & cameraName = ""); virtual bool init(const std::string & calibrationFolder = ".", const std::string & cameraName = "");
virtual bool isCalibrated() const; virtual bool isCalibrated() const;
virtual std::string getSerial() const; virtual std::string getSerial() const;
@@ -402,6 +403,7 @@ private:
int presetRGB_; int presetRGB_;
int presetDepth_; int presetDepth_;
bool computeOdometry_; bool computeOdometry_;
bool depthScaledToRGBSize_;
int motionSeq_[2]; int motionSeq_[2];
rs::slam::slam * slam_; rs::slam::slam * slam_;
@@ -414,7 +416,7 @@ private:
#endif #endif
}; };
///////////////////////// /////////////////////////
// CameraRealSense // CameraRealSense2
///////////////////////// /////////////////////////
class slam_event_handler; class slam_event_handler;
class RTABMAP_EXP CameraRealSense2 : class RTABMAP_EXP CameraRealSense2 :

View File

@@ -2623,6 +2623,7 @@ CameraRealSense::CameraRealSense(
presetRGB_(presetRGB), presetRGB_(presetRGB),
presetDepth_(presetDepth), presetDepth_(presetDepth),
computeOdometry_(computeOdometry), computeOdometry_(computeOdometry),
depthScaledToRGBSize_(false),
slam_(0) slam_(0)
#endif #endif
{ {
@@ -3132,7 +3133,8 @@ SensorData CameraRealSense::captureImage(CameraInfo * info)
cv::Mat depth; cv::Mat depth;
if (color_intrin.width % depth_intrin.width == 0 && color_intrin.height % depth_intrin.height == 0 && if (color_intrin.width % depth_intrin.width == 0 && color_intrin.height % depth_intrin.height == 0 &&
depth_intrin.width < color_intrin.width && depth_intrin.width < color_intrin.width &&
depth_intrin.height < color_intrin.height) depth_intrin.height < color_intrin.height &&
!depthScaledToRGBSize_)
{ {
//we can keep the depth image size as is //we can keep the depth image size as is
depth = cv::Mat::zeros(cv::Size(depth_intrin.width, depth_intrin.height), CV_16UC1); depth = cv::Mat::zeros(cv::Size(depth_intrin.width, depth_intrin.height), CV_16UC1);

View File

@@ -859,7 +859,8 @@ Transform OdometryORBSLAM2::computeTransform(
data.imageRaw().rows != data.depthOrRightRaw().rows || data.imageRaw().rows != data.depthOrRightRaw().rows ||
data.imageRaw().cols != data.depthOrRightRaw().cols) data.imageRaw().cols != data.depthOrRightRaw().cols)
{ {
UERROR("Not supported input!"); UERROR("Not supported input! RGB (%dx%d) and depth (%dx%d) should have the same size.",
data.imageRaw().cols, data.imageRaw().rows, data.depthOrRightRaw().cols, data.depthOrRightRaw().rows);
return t; return t;
} }

View File

@@ -564,6 +564,7 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
connect(_ui->comboBox_realsensePresetRGB, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->comboBox_realsensePresetRGB, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->comboBox_realsensePresetDepth, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->comboBox_realsensePresetDepth, SIGNAL(currentIndexChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->checkbox_realsenseOdom, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->checkbox_realsenseOdom, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->checkbox_realsenseDepthScaledToRGBSize, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->checkbox_rs2_emitter, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->checkbox_rs2_emitter, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->checkbox_rs2_irDepth, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->checkbox_rs2_irDepth, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
@@ -1607,6 +1608,7 @@ void PreferencesDialog::resetSettings(QGroupBox * groupBox)
_ui->comboBox_realsensePresetRGB->setCurrentIndex(0); _ui->comboBox_realsensePresetRGB->setCurrentIndex(0);
_ui->comboBox_realsensePresetDepth->setCurrentIndex(2); _ui->comboBox_realsensePresetDepth->setCurrentIndex(2);
_ui->checkbox_realsenseOdom->setChecked(false); _ui->checkbox_realsenseOdom->setChecked(false);
_ui->checkbox_realsenseDepthScaledToRGBSize->setChecked(false);
_ui->checkbox_rs2_emitter->setChecked(true); _ui->checkbox_rs2_emitter->setChecked(true);
_ui->checkbox_rs2_irDepth->setChecked(false); _ui->checkbox_rs2_irDepth->setChecked(false);
_ui->lineEdit_openniOniPath->clear(); _ui->lineEdit_openniOniPath->clear();
@@ -2002,6 +2004,7 @@ void PreferencesDialog::readCameraSettings(const QString & filePath)
_ui->comboBox_realsensePresetRGB->setCurrentIndex(settings.value("presetRGB", _ui->comboBox_realsensePresetRGB->currentIndex()).toInt()); _ui->comboBox_realsensePresetRGB->setCurrentIndex(settings.value("presetRGB", _ui->comboBox_realsensePresetRGB->currentIndex()).toInt());
_ui->comboBox_realsensePresetDepth->setCurrentIndex(settings.value("presetDepth", _ui->comboBox_realsensePresetDepth->currentIndex()).toInt()); _ui->comboBox_realsensePresetDepth->setCurrentIndex(settings.value("presetDepth", _ui->comboBox_realsensePresetDepth->currentIndex()).toInt());
_ui->checkbox_realsenseOdom->setChecked(settings.value("odom", _ui->checkbox_realsenseOdom->isChecked()).toBool()); _ui->checkbox_realsenseOdom->setChecked(settings.value("odom", _ui->checkbox_realsenseOdom->isChecked()).toBool());
_ui->checkbox_realsenseDepthScaledToRGBSize->setChecked(settings.value("depthScaled", _ui->checkbox_realsenseDepthScaledToRGBSize->isChecked()).toBool());
settings.endGroup(); // RealSense settings.endGroup(); // RealSense
settings.beginGroup("RealSense2"); settings.beginGroup("RealSense2");
@@ -2421,6 +2424,7 @@ void PreferencesDialog::writeCameraSettings(const QString & filePath) const
settings.setValue("presetRGB", _ui->comboBox_realsensePresetRGB->currentIndex()); settings.setValue("presetRGB", _ui->comboBox_realsensePresetRGB->currentIndex());
settings.setValue("presetDepth", _ui->comboBox_realsensePresetDepth->currentIndex()); settings.setValue("presetDepth", _ui->comboBox_realsensePresetDepth->currentIndex());
settings.setValue("odom", _ui->checkbox_realsenseOdom->isChecked()); settings.setValue("odom", _ui->checkbox_realsenseOdom->isChecked());
settings.setValue("depthScaled", _ui->checkbox_realsenseDepthScaledToRGBSize->isChecked());
settings.endGroup(); // RealSense settings.endGroup(); // RealSense
settings.beginGroup("RealSense2"); settings.beginGroup("RealSense2");
@@ -4966,6 +4970,7 @@ Camera * PreferencesDialog::createCamera(bool useRawImages, bool useColor)
_ui->checkbox_realsenseOdom->isChecked(), _ui->checkbox_realsenseOdom->isChecked(),
this->getGeneralInputRate(), this->getGeneralInputRate(),
this->getSourceLocalTransform()); this->getSourceLocalTransform());
((CameraRealSense*)camera)->setDepthScaledToRGBSize(_ui->checkbox_realsenseDepthScaledToRGBSize->isChecked());
} }
} }
else if (driver == kSrcRealSense2) else if (driver == kSrcRealSense2)

View File

@@ -94,9 +94,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-439</y> <y>-396</y>
<width>680</width> <width>681</width>
<height>2836</height> <height>2811</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_16"> <layout class="QVBoxLayout" name="verticalLayout_16">
@@ -2978,7 +2978,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<item> <item>
<widget class="QStackedWidget" name="stackedWidget_rgbd"> <widget class="QStackedWidget" name="stackedWidget_rgbd">
<property name="currentIndex"> <property name="currentIndex">
<number>9</number> <number>6</number>
</property> </property>
<widget class="QWidget" name="page_32"> <widget class="QWidget" name="page_32">
<layout class="QVBoxLayout" name="verticalLayout_63"> <layout class="QVBoxLayout" name="verticalLayout_63">
@@ -3526,7 +3526,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<string>RealSense</string> <string>RealSense</string>
</property> </property>
<layout class="QGridLayout" name="gridLayout_73" columnstretch="0,1"> <layout class="QGridLayout" name="gridLayout_73" columnstretch="0,1">
<item row="3" column="0"> <item row="4" column="0">
<spacer name="verticalSpacer_51"> <spacer name="verticalSpacer_51">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@@ -3632,6 +3632,29 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1">
<widget class="QLabel" name="label_realsenseOdom_2">
<property name="text">
<string>Depth image scaled to RGB image size.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkbox_realsenseDepthScaledToRGBSize">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>