ImageView: added depth colormap menu option

This commit is contained in:
matlabbe
2018-08-17 15:28:23 -04:00
parent 67aa4cd28e
commit 3ce6de573d
9 changed files with 118 additions and 29 deletions

View File

@@ -136,7 +136,7 @@ void CameraViewer::showImage(const rtabmap::SensorData & data)
}
if(!data.depthOrRightRaw().empty())
{
imageView_->setImageDepth(uCvMat2QImage(util2d::decimate(data.depthOrRightRaw(), validDecimationValue_)));
imageView_->setImageDepth(util2d::decimate(data.depthOrRightRaw(), validDecimationValue_));
}
if(!data.depthOrRightRaw().empty() &&

View File

@@ -157,7 +157,7 @@ void DataRecorder::showImage(const cv::Mat & image, const cv::Mat & depth)
{
processingImages_ = true;
imageView_->setImage(uCvMat2QImage(image));
imageView_->setImageDepth(uCvMat2QImage(depth));
imageView_->setImageDepth(depth);
label_->setText(tr("Images=%1 (~%2 MB)").arg(count_).arg(totalSizeKB_/1000));
processingImages_ = false;
}

View File

@@ -3431,7 +3431,7 @@ void DatabaseViewer::update(int value,
{
//image
QImage img;
QImage imgDepth;
cv::Mat imgDepth;
if(dbDriver_)
{
SensorData data;
@@ -3451,7 +3451,7 @@ void DatabaseViewer::update(int value,
depth = util2d::fillDepthHoles(depth, ui_->spinBox_mesh_fillDepthHoles->value(), float(ui_->spinBox_mesh_depthError->value())/100.0f);
}
}
imgDepth = uCvMat2QImage(depth);
imgDepth = depth;
}
std::list<int> ids;
@@ -3931,12 +3931,13 @@ void DatabaseViewer::update(int value,
ULOGGER_DEBUG("Image is empty");
}
if(!imgDepth.isNull())
if(!imgDepth.empty())
{
view->setImageDepth(imgDepth);
if(img.isNull())
{
rect = imgDepth.rect();
rect.setWidth(imgDepth.cols);
rect.setHeight(imgDepth.rows);
}
}
else
@@ -4223,7 +4224,7 @@ void DatabaseViewer::updateStereo(const SensorData * data)
ui_->graphicsView_stereo->setImageDepthShown(true);
ui_->graphicsView_stereo->setImage(uCvMat2QImage(data->imageRaw()));
ui_->graphicsView_stereo->setImageDepth(uCvMat2QImage(data->depthOrRightRaw()));
ui_->graphicsView_stereo->setImageDepth(data->depthOrRightRaw());
// Draw lines between corresponding features...
for(unsigned int i=0; i<kpts.size(); ++i)

View File

@@ -38,6 +38,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QVBoxLayout>
#include <QGraphicsRectItem>
#include "rtabmap/utilite/ULogger.h"
#include "rtabmap/utilite/UCv2Qt.h"
#include "rtabmap/gui/KeypointItem.h"
#include "rtabmap/core/util2d.h"
@@ -198,6 +199,24 @@ ImageView::ImageView(QWidget * parent) :
group->addAction(_graphicsViewScaled);
group->addAction(_graphicsViewScaledToHeight);
group->addAction(_graphicsViewNoScaling);
QMenu * colorMap = _menu->addMenu("Depth color map");
_colorMapWhiteToBlack = colorMap->addAction(tr("White to black"));
_colorMapWhiteToBlack->setCheckable(true);
_colorMapWhiteToBlack->setChecked(true);
_colorMapBlackToWhite = colorMap->addAction(tr("Black to white"));
_colorMapBlackToWhite->setCheckable(true);
_colorMapBlackToWhite->setChecked(false);
_colorMapRedToBlue = colorMap->addAction(tr("Red to blue"));
_colorMapRedToBlue->setCheckable(true);
_colorMapRedToBlue->setChecked(false);
_colorMapBlueToRed = colorMap->addAction(tr("Blue to red"));
_colorMapBlueToRed->setCheckable(true);
_colorMapBlueToRed->setChecked(false);
group = new QActionGroup(this);
group->addAction(_colorMapWhiteToBlack);
group->addAction(_colorMapBlackToWhite);
group->addAction(_colorMapRedToBlue);
group->addAction(_colorMapBlueToRed);
_setAlpha = _menu->addAction(tr("Set transparency..."));
_saveImage = _menu->addAction(tr("Save picture..."));
_saveImage->setEnabled(false);
@@ -224,6 +243,8 @@ void ImageView::saveSettings(QSettings & settings, const QString & group) const
settings.setValue("bg_color", this->getDefaultBackgroundColor());
settings.setValue("graphics_view", this->isGraphicsViewMode());
settings.setValue("graphics_view_scale", this->isGraphicsViewScaled());
settings.setValue("graphics_view_scale_to_height", this->isGraphicsViewScaledToHeight());
settings.setValue("colormap", _colorMapWhiteToBlack->isChecked()?0:_colorMapBlackToWhite->isChecked()?1:_colorMapRedToBlue->isChecked()?2:3);
if(!group.isEmpty())
{
settings.endGroup();
@@ -245,6 +266,12 @@ void ImageView::loadSettings(QSettings & settings, const QString & group)
this->setDefaultBackgroundColor(settings.value("bg_color", this->getDefaultBackgroundColor()).value<QColor>());
this->setGraphicsViewMode(settings.value("graphics_view", this->isGraphicsViewMode()).toBool());
this->setGraphicsViewScaled(settings.value("graphics_view_scale", this->isGraphicsViewScaled()).toBool());
this->setGraphicsViewScaledToHeight(settings.value("graphics_view_scale_to_height", this->isGraphicsViewScaledToHeight()).toBool());
int colorMap = settings.value("colormap", 0).toInt();
_colorMapWhiteToBlack->setChecked(colorMap==0);
_colorMapBlackToWhite->setChecked(colorMap==1);
_colorMapRedToBlue->setChecked(colorMap==2);
_colorMapBlueToRed->setChecked(colorMap==3);
if(!group.isEmpty())
{
settings.endGroup();
@@ -689,6 +716,11 @@ void ImageView::contextMenuEvent(QContextMenuEvent * e)
this->setGraphicsViewScaledToHeight(_graphicsViewScaledToHeight->isChecked());
Q_EMIT configChanged();
}
else if(action == _colorMapBlackToWhite || action == _colorMapWhiteToBlack || action == _colorMapRedToBlue || action == _colorMapBlueToRed)
{
this->setImageDepth(_imageDepthCv);
Q_EMIT configChanged();
}
else if(action == _setAlpha)
{
bool ok = false;
@@ -862,6 +894,25 @@ void ImageView::setImage(const QImage & image)
}
}
void ImageView::setImageDepth(const cv::Mat & imageDepth)
{
_imageDepthCv = imageDepth;
uCvQtDepthColorMap colorMap = uCvQtDepthWhiteToBlack;
if(_colorMapBlackToWhite->isChecked())
{
colorMap = uCvQtDepthBlackToWhite;
}
else if(_colorMapRedToBlue->isChecked())
{
colorMap = uCvQtDepthRedToBlue;
}
else if(_colorMapBlueToRed->isChecked())
{
colorMap = uCvQtDepthBlueToRed;
}
setImageDepth(uCvMat2QImage(_imageDepthCv, true, colorMap));
}
void ImageView::setImageDepth(const QImage & imageDepth)
{
_imageDepth = QPixmap::fromImage(imageDepth);

View File

@@ -1352,7 +1352,7 @@ void MainWindow::processOdometry(const rtabmap::OdometryEvent & odom, bool dataI
_odomImageShow = _ui->imageView_odometry->isImageShown();
_odomImageDepthShow = _ui->imageView_odometry->isImageDepthShown();
}
_ui->imageView_odometry->setImageDepth(uCvMat2QImage(odom.data().imageRaw()));
_ui->imageView_odometry->setImageDepth(odom.data().imageRaw());
_ui->imageView_odometry->setImageShown(true);
_ui->imageView_odometry->setImageDepthShown(true);
}
@@ -1368,7 +1368,7 @@ void MainWindow::processOdometry(const rtabmap::OdometryEvent & odom, bool dataI
_ui->imageView_odometry->setImage(uCvMat2QImage(odom.data().imageRaw()));
if(_ui->imageView_odometry->isImageDepthShown() && !odom.data().depthOrRightRaw().empty())
{
_ui->imageView_odometry->setImageDepth(uCvMat2QImage(odom.data().depthOrRightRaw()));
_ui->imageView_odometry->setImageDepth(odom.data().depthOrRightRaw());
}
if( odom.info().type == (int)Odometry::kTypeF2M ||
@@ -1748,31 +1748,23 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
{
UCvMat2QImageThread qimageThread(signature.sensorData().imageRaw());
UCvMat2QImageThread qimageLoopThread(loopSignature.sensorData().imageRaw());
UCvMat2QImageThread qdepthThread(signature.sensorData().depthOrRightRaw());
UCvMat2QImageThread qdepthLoopThread(loopSignature.sensorData().depthOrRightRaw());
qimageThread.start();
qdepthThread.start();
qimageLoopThread.start();
qdepthLoopThread.start();
qimageThread.join();
qdepthThread.join();
qimageLoopThread.join();
qdepthLoopThread.join();
QImage img = qimageThread.getQImage();
QImage lcImg = qimageLoopThread.getQImage();
QImage depth = qdepthThread.getQImage();
QImage lcDepth = qdepthLoopThread.getQImage();
UDEBUG("time= %d ms", time.restart());
if(!img.isNull())
{
_ui->imageView_source->setImage(img);
}
if(!depth.isNull())
if(!signature.sensorData().depthOrRightRaw().empty())
{
_ui->imageView_source->setImageDepth(depth);
_ui->imageView_source->setImageDepth(signature.sensorData().depthOrRightRaw());
}
if(img.isNull() && depth.isNull())
if(img.isNull() && signature.sensorData().depthOrRightRaw().empty())
{
QRect sceneRect;
if(signature.sensorData().cameraModels().size())
@@ -1796,9 +1788,9 @@ void MainWindow::processStats(const rtabmap::Statistics & stat)
{
_ui->imageView_loopClosure->setImage(lcImg);
}
if(!lcDepth.isNull())
if(!loopSignature.sensorData().depthOrRightRaw().empty())
{
_ui->imageView_loopClosure->setImageDepth(lcDepth);
_ui->imageView_loopClosure->setImageDepth(loopSignature.sensorData().depthOrRightRaw());
}
if(_ui->imageView_loopClosure->sceneRect().isNull())
{

View File

@@ -418,7 +418,7 @@ void OdometryViewer::processData(const rtabmap::OdometryEvent & odom)
odomImageShow_ = imageView_->isImageShown();
odomImageDepthShow_ = imageView_->isImageDepthShown();
}
imageView_->setImageDepth(uCvMat2QImage(odom.data().imageRaw()));
imageView_->setImageDepth(odom.data().imageRaw());
imageView_->setImageShown(true);
imageView_->setImageDepthShown(true);
}
@@ -434,7 +434,7 @@ void OdometryViewer::processData(const rtabmap::OdometryEvent & odom)
imageView_->setImage(uCvMat2QImage(odom.data().imageRaw()));
if(imageView_->isImageDepthShown())
{
imageView_->setImageDepth(uCvMat2QImage(odom.data().depthOrRightRaw()));
imageView_->setImageDepth(odom.data().depthOrRightRaw());
}
if( odom.info().type == Odometry::kTypeF2M ||