Added Source/Mirroring parameter for convenience

This commit is contained in:
matlabbe
2015-02-28 18:09:22 -05:00
parent 395dac5777
commit cf69f17925
9 changed files with 100 additions and 43 deletions
+3
View File
@@ -56,10 +56,12 @@ public:
//getters //getters
void getImageSize(unsigned int & width, unsigned int & height); void getImageSize(unsigned int & width, unsigned int & height);
float getImageRate() const {return _imageRate;} float getImageRate() const {return _imageRate;}
bool isMirroringEnabled() const {return _mirroring;}
//setters //setters
void setImageRate(float imageRate) {_imageRate = imageRate;} void setImageRate(float imageRate) {_imageRate = imageRate;}
void setImageSize(unsigned int width, unsigned int height); void setImageSize(unsigned int width, unsigned int height);
void setMirroringEnabled(bool enabled) {_mirroring = enabled;}
void setCalibration(const std::string & fileName); void setCalibration(const std::string & fileName);
void setCalibration(const cv::Mat & cameraMatrix, const cv::Mat & distorsionCoefficients); void setCalibration(const cv::Mat & cameraMatrix, const cv::Mat & distorsionCoefficients);
@@ -81,6 +83,7 @@ private:
float _imageRate; float _imageRate;
unsigned int _imageWidth; unsigned int _imageWidth;
unsigned int _imageHeight; unsigned int _imageHeight;
bool _mirroring;
UTimer * _frameRateTimer; UTimer * _frameRateTimer;
cv::Mat _k; // camera_matrix cv::Mat _k; // camera_matrix
cv::Mat _d; // distorsion_coefficients cv::Mat _d; // distorsion_coefficients
@@ -77,6 +77,7 @@ public:
//getters //getters
float getImageRate() const {return _imageRate;} float getImageRate() const {return _imageRate;}
const Transform & getLocalTransform() const {return _localTransform;} const Transform & getLocalTransform() const {return _localTransform;}
bool isMirroringEnabled() const {return _mirroring;}
float getFx() const {return _fx;} float getFx() const {return _fx;}
float getFy() const {return _fy;} float getFy() const {return _fy;}
float getCx() const {return _cx;} float getCx() const {return _cx;}
@@ -85,6 +86,7 @@ public:
//setters //setters
void setImageRate(float imageRate) {_imageRate = imageRate;} void setImageRate(float imageRate) {_imageRate = imageRate;}
void setLocalTransform(const Transform & localTransform) {_localTransform= localTransform;} void setLocalTransform(const Transform & localTransform) {_localTransform= localTransform;}
void setMirroringEnabled(bool mirroring) {_mirroring = mirroring;}
void setFx(float fx) {_fx = fx;} void setFx(float fx) {_fx = fx;}
void setFy(float fy) {_fy = fy;} void setFy(float fy) {_fy = fy;}
void setCx(float cx) {_cx = cx;} void setCx(float cx) {_cx = cx;}
@@ -108,6 +110,7 @@ protected:
private: private:
float _imageRate; float _imageRate;
Transform _localTransform; Transform _localTransform;
bool _mirroring;
UTimer * _frameRateTimer; UTimer * _frameRateTimer;
float _fx; float _fx;
float _fy; float _fy;
+5
View File
@@ -50,6 +50,7 @@ Camera::Camera(float imageRate,
_imageRate(imageRate), _imageRate(imageRate),
_imageWidth(imageWidth), _imageWidth(imageWidth),
_imageHeight(imageHeight), _imageHeight(imageHeight),
_mirroring(false),
_frameRateTimer(new UTimer()) _frameRateTimer(new UTimer())
{ {
} }
@@ -177,6 +178,10 @@ cv::Mat Camera::takeImage()
cv::Mat temp = img.clone(); cv::Mat temp = img.clone();
cv::undistort(temp, img, _k, _d); cv::undistort(temp, img, _k, _d);
} }
if(!img.empty() && _mirroring)
{
cv::flip(img,img,1);
}
UDEBUG("Time capturing image = %fs", timer.ticks()); UDEBUG("Time capturing image = %fs", timer.ticks());
return img; return img;
} }
+9
View File
@@ -118,6 +118,15 @@ void CameraRGBD::takeImage(cv::Mat & rgb, cv::Mat & depth, float & fx, float & f
{ {
cy = _cy; // override if set cy = _cy; // override if set
} }
if(!rgb.empty() && !depth.empty() && _mirroring)
{
cv::flip(rgb,rgb,1);
cv::flip(depth,depth,1);
if(cx != 0.0f)
{
cx = float(rgb.cols) - cx;
}
}
UDEBUG("Time capturing image = %fs", timer.ticks()); UDEBUG("Time capturing image = %fs", timer.ticks());
} }
+5 -2
View File
@@ -30,13 +30,16 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QtGui/QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QtCore/QMetaType> #include <QtCore/QMetaType>
#ifndef Q_MOC_RUN
#include "rtabmap/gui/CloudViewer.h" #include "rtabmap/gui/CloudViewer.h"
#include "rtabmap/core/util3d.h"
#include "rtabmap/core/RtabmapEvent.h"
#endif
#include "rtabmap/utilite/UStl.h" #include "rtabmap/utilite/UStl.h"
#include "rtabmap/utilite/UConversion.h" #include "rtabmap/utilite/UConversion.h"
#include "rtabmap/utilite/UEventsHandler.h" #include "rtabmap/utilite/UEventsHandler.h"
#include "rtabmap/utilite/ULogger.h" #include "rtabmap/utilite/ULogger.h"
#include "rtabmap/core/util3d.h"
#include "rtabmap/core/RtabmapEvent.h"
#include "rtabmap/core/OdometryEvent.h" #include "rtabmap/core/OdometryEvent.h"
using namespace rtabmap; using namespace rtabmap;
@@ -155,6 +155,7 @@ public:
// source panel // source panel
double getGeneralInputRate() const; double getGeneralInputRate() const;
bool isSourceMirroring() const;
bool isSourceImageUsed() const; bool isSourceImageUsed() const;
bool isSourceDatabaseUsed() const; bool isSourceDatabaseUsed() const;
bool isSourceOpenniUsed() const; bool isSourceOpenniUsed() const;
+10
View File
@@ -1905,6 +1905,14 @@ void MainWindow::applyPrefSettings(PreferencesDialog::PANEL_FLAGS flags)
((CameraOpenNI2*)_camera->cameraRGBD())->setGain(_preferencesDialog->getSourceOpenni2Gain()); ((CameraOpenNI2*)_camera->cameraRGBD())->setGain(_preferencesDialog->getSourceOpenni2Gain());
} }
} }
if(_camera->camera())
{
_camera->camera()->setMirroringEnabled(_preferencesDialog->isSourceMirroring());
}
if(_camera->cameraRGBD())
{
_camera->cameraRGBD()->setMirroringEnabled(_preferencesDialog->isSourceMirroring());
}
} }
if(_dbReader) if(_dbReader)
{ {
@@ -2633,6 +2641,7 @@ void MainWindow::startDetection()
((CameraOpenNI2*)camera)->setGain(_preferencesDialog->getSourceOpenni2Gain()); ((CameraOpenNI2*)camera)->setGain(_preferencesDialog->getSourceOpenni2Gain());
} }
} }
camera->setMirroringEnabled(_preferencesDialog->isSourceMirroring());
_camera = new CameraThread(camera); _camera = new CameraThread(camera);
if(_odomThread) if(_odomThread)
@@ -2738,6 +2747,7 @@ void MainWindow::startDetection()
camera = 0; camera = 0;
return; return;
} }
camera->setMirroringEnabled(_preferencesDialog->isSourceMirroring());
_camera = new CameraThread(camera); _camera = new CameraThread(camera);
} }
+12
View File
@@ -122,6 +122,7 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
#ifdef _WIN32 #ifdef _WIN32
_ui->radioButton_openni2->setChecked(true); _ui->radioButton_openni2->setChecked(true);
_ui->radioButton_opennipcl->setChecked(false); _ui->radioButton_opennipcl->setChecked(false);
showOpenNI2GroupBox(true);
#endif #endif
if(RTABMAP_NONFREE == 0) if(RTABMAP_NONFREE == 0)
@@ -241,6 +242,7 @@ PreferencesDialog::PreferencesDialog(QWidget * parent) :
//Source panel //Source panel
connect(_ui->general_doubleSpinBox_imgRate, SIGNAL(valueChanged(double)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->general_doubleSpinBox_imgRate, SIGNAL(valueChanged(double)), this, SLOT(makeObsoleteSourcePanel()));
connect(_ui->source_mirroring, SIGNAL(stateChanged(int)), this, SLOT(makeObsoleteSourcePanel()));
//Image source //Image source
connect(_ui->groupBox_sourceImage, SIGNAL(toggled(bool)), this, SLOT(makeObsoleteSourcePanel())); connect(_ui->groupBox_sourceImage, SIGNAL(toggled(bool)), this, SLOT(makeObsoleteSourcePanel()));
_ui->stackedWidget_image->setCurrentIndex(_ui->source_comboBox_image_type->currentIndex()); _ui->stackedWidget_image->setCurrentIndex(_ui->source_comboBox_image_type->currentIndex());
@@ -888,6 +890,7 @@ void PreferencesDialog::resetSettings(QGroupBox * groupBox)
else if(groupBox->objectName() == _ui->groupBox_source0->objectName()) else if(groupBox->objectName() == _ui->groupBox_source0->objectName())
{ {
_ui->general_doubleSpinBox_imgRate->setValue(30.0); _ui->general_doubleSpinBox_imgRate->setValue(30.0);
_ui->source_mirroring->setChecked(false);
_ui->groupBox_sourceImage->setChecked(false); _ui->groupBox_sourceImage->setChecked(false);
_ui->source_spinBox_imgWidth->setValue(0); _ui->source_spinBox_imgWidth->setValue(0);
@@ -1143,6 +1146,7 @@ void PreferencesDialog::readCameraSettings(const QString & filePath)
settings.beginGroup("Camera"); settings.beginGroup("Camera");
_ui->groupBox_sourceImage->setChecked(settings.value("imageUsed", _ui->groupBox_sourceImage->isChecked()).toBool()); _ui->groupBox_sourceImage->setChecked(settings.value("imageUsed", _ui->groupBox_sourceImage->isChecked()).toBool());
_ui->general_doubleSpinBox_imgRate->setValue(settings.value("imgRate", _ui->general_doubleSpinBox_imgRate->value()).toDouble()); _ui->general_doubleSpinBox_imgRate->setValue(settings.value("imgRate", _ui->general_doubleSpinBox_imgRate->value()).toDouble());
_ui->source_mirroring->setChecked(settings.value("mirroring", _ui->source_mirroring->isChecked()).toBool());
_ui->source_comboBox_image_type->setCurrentIndex(settings.value("type", _ui->source_comboBox_image_type->currentIndex()).toInt()); _ui->source_comboBox_image_type->setCurrentIndex(settings.value("type", _ui->source_comboBox_image_type->currentIndex()).toInt());
_ui->source_spinBox_imgWidth->setValue(settings.value("imgWidth",_ui->source_spinBox_imgWidth->value()).toInt()); _ui->source_spinBox_imgWidth->setValue(settings.value("imgWidth",_ui->source_spinBox_imgWidth->value()).toInt());
_ui->source_spinBox_imgheight->setValue(settings.value("imgHeight",_ui->source_spinBox_imgheight->value()).toInt()); _ui->source_spinBox_imgheight->setValue(settings.value("imgHeight",_ui->source_spinBox_imgheight->value()).toInt());
@@ -1391,6 +1395,7 @@ void PreferencesDialog::writeCameraSettings(const QString & filePath) const
settings.beginGroup("Camera"); settings.beginGroup("Camera");
settings.setValue("imageUsed", _ui->groupBox_sourceImage->isChecked()); settings.setValue("imageUsed", _ui->groupBox_sourceImage->isChecked());
settings.setValue("imgRate", _ui->general_doubleSpinBox_imgRate->value()); settings.setValue("imgRate", _ui->general_doubleSpinBox_imgRate->value());
settings.setValue("mirroring", _ui->source_mirroring->isChecked());
settings.setValue("type", _ui->source_comboBox_image_type->currentIndex()); settings.setValue("type", _ui->source_comboBox_image_type->currentIndex());
settings.setValue("imgWidth", _ui->source_spinBox_imgWidth->value()); settings.setValue("imgWidth", _ui->source_spinBox_imgWidth->value());
settings.setValue("imgHeight", _ui->source_spinBox_imgheight->value()); settings.setValue("imgHeight", _ui->source_spinBox_imgheight->value());
@@ -3046,6 +3051,10 @@ double PreferencesDialog::getGeneralInputRate() const
{ {
return _ui->general_doubleSpinBox_imgRate->value(); return _ui->general_doubleSpinBox_imgRate->value();
} }
bool PreferencesDialog::isSourceMirroring() const
{
return _ui->source_mirroring->isChecked();
}
bool PreferencesDialog::isSourceImageUsed() const bool PreferencesDialog::isSourceImageUsed() const
{ {
return _ui->groupBox_sourceImage->isChecked(); return _ui->groupBox_sourceImage->isChecked();
@@ -3406,6 +3415,7 @@ void PreferencesDialog::testOdometry(int type)
((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain()); ((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain());
} }
} }
camera->setMirroringEnabled(isSourceMirroring());
if(camera) if(camera)
@@ -3573,6 +3583,7 @@ void PreferencesDialog::testRGBDCamera()
((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain()); ((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain());
} }
} }
camera->setMirroringEnabled(isSourceMirroring());
if(camera) if(camera)
@@ -3671,6 +3682,7 @@ void PreferencesDialog::calibrate()
((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain()); ((CameraOpenNI2*)camera)->setGain(getSourceOpenni2Gain());
} }
} }
camera->setMirroringEnabled(isSourceMirroring());
if(camera) if(camera)
+52 -41
View File
@@ -63,9 +63,9 @@
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>-203</y> <y>0</y>
<width>744</width> <width>737</width>
<height>1101</height> <height>1320</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_16"> <layout class="QVBoxLayout" name="verticalLayout_16">
@@ -86,7 +86,7 @@
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>20</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="page_22"> <widget class="QWidget" name="page_22">
<layout class="QVBoxLayout" name="verticalLayout_29"> <layout class="QVBoxLayout" name="verticalLayout_29">
@@ -1288,6 +1288,20 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="1">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Mirroring mode (flip image horizontally). It has no effect on database source.</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="source_mirroring">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>
@@ -1719,34 +1733,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
<property name="title"> <property name="title">
<string>OpenNI 2</string> <string>OpenNI 2</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_6"> <layout class="QGridLayout" name="gridLayout_54" columnstretch="0,1">
<item row="6" column="0">
<widget class="QSpinBox" name="openni2_gain">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QSpinBox" name="openni2_exposure">
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="openni2_autoExposure">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QCheckBox" name="openni2_autoWhiteBalance"> <widget class="QCheckBox" name="openni2_autoWhiteBalance">
<property name="text"> <property name="text">
@@ -1767,6 +1754,16 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0">
<widget class="QCheckBox" name="openni2_autoExposure">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QLabel" name="label_218"> <widget class="QLabel" name="label_218">
<property name="text"> <property name="text">
@@ -1777,7 +1774,14 @@ 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"> <item row="2" column="0">
<widget class="QSpinBox" name="openni2_exposure">
<property name="maximum">
<number>65535</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_219"> <widget class="QLabel" name="label_219">
<property name="text"> <property name="text">
<string>Exposure.</string> <string>Exposure.</string>
@@ -1787,7 +1791,17 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="1"> <item row="3" column="0">
<widget class="QSpinBox" name="openni2_gain">
<property name="maximum">
<number>1000</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_220"> <widget class="QLabel" name="label_220">
<property name="text"> <property name="text">
<string>Gain.</string> <string>Gain.</string>
@@ -1797,7 +1811,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="4" column="0">
<widget class="QCheckBox" name="openni2_mirroring"> <widget class="QCheckBox" name="openni2_mirroring">
<property name="text"> <property name="text">
<string/> <string/>
@@ -1807,7 +1821,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="4" column="1">
<widget class="QLabel" name="label_223"> <widget class="QLabel" name="label_223">
<property name="text"> <property name="text">
<string>Mirroring.</string> <string>Mirroring.</string>
@@ -1878,10 +1892,7 @@ when using the file type, logs are saved in LogRtabmap.txt (located in the worki
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QFormLayout" name="formLayout_21"> <layout class="QGridLayout" name="gridLayout_55" columnstretch="0,1">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::ExpandingFieldsGrow</enum>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QDoubleSpinBox" name="doubleSpinBox_openniFx"> <widget class="QDoubleSpinBox" name="doubleSpinBox_openniFx">
<property name="maximum"> <property name="maximum">
@@ -4720,7 +4731,7 @@ When set to false, no new words are added to dictionary, so no more updates are
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item> <item>
<layout class="QFormLayout" name="formLayout_9"> <layout class="QGridLayout" name="gridLayout_10" columnstretch="0,1">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QComboBox" name="comboBox_vh_strategy"> <widget class="QComboBox" name="comboBox_vh_strategy">
<property name="sizeAdjustPolicy"> <property name="sizeAdjustPolicy">