mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-03 01:50:24 +08:00
ImageView: added depth colormap menu option
This commit is contained in:
@@ -85,6 +85,7 @@ public:
|
||||
void addFeature(int id, const cv::KeyPoint & kpt, float depth, QColor color);
|
||||
void addLine(float x1, float y1, float x2, float y2, QColor color, const QString & text = QString());
|
||||
void setImage(const QImage & image);
|
||||
void setImageDepth(const cv::Mat & imageDepth);
|
||||
void setImageDepth(const QImage & image);
|
||||
void setFeatureColor(int id, QColor color);
|
||||
void setFeaturesColor(QColor color);
|
||||
@@ -133,6 +134,10 @@ private:
|
||||
QAction * _graphicsViewScaled;
|
||||
QAction * _graphicsViewScaledToHeight;
|
||||
QAction * _graphicsViewNoScaling;
|
||||
QAction * _colorMapWhiteToBlack;
|
||||
QAction * _colorMapBlackToWhite;
|
||||
QAction * _colorMapRedToBlue;
|
||||
QAction * _colorMapBlueToRed;
|
||||
QMenu * _scaleMenu;
|
||||
|
||||
QGraphicsView * _graphicsView;
|
||||
@@ -142,6 +147,7 @@ private:
|
||||
QGraphicsPixmapItem * _imageDepthItem;
|
||||
QPixmap _image;
|
||||
QPixmap _imageDepth;
|
||||
cv::Mat _imageDepthCv;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -21,11 +21,19 @@
|
||||
#define UCV2QT_H_
|
||||
|
||||
#include <QtGui/QImage>
|
||||
#include <QtGui/QColor>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <rtabmap/utilite/UMath.h>
|
||||
#include <rtabmap/utilite/UThread.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum uCvQtDepthColorMap{
|
||||
uCvQtDepthWhiteToBlack,
|
||||
uCvQtDepthBlackToWhite,
|
||||
uCvQtDepthRedToBlue,
|
||||
uCvQtDepthBlueToRed
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a cv::Mat image to a QImage. Support
|
||||
* depth (float32, uint16) image and RGB/BGR 8bits images.
|
||||
@@ -33,7 +41,7 @@
|
||||
* @param isBgr if 3 channels, it is BGR or RGB order.
|
||||
* @return the QImage
|
||||
*/
|
||||
inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true)
|
||||
inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true, uCvQtDepthColorMap colorMap = uCvQtDepthWhiteToBlack)
|
||||
{
|
||||
QImage qtemp;
|
||||
if(!image.empty() && image.depth() == CV_8U)
|
||||
@@ -66,7 +74,8 @@ inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true)
|
||||
// mono grayscale
|
||||
qtemp = QImage(image.data, image.cols, image.rows, image.cols, QImage::Format_Indexed8).copy();
|
||||
QVector<QRgb> my_table;
|
||||
for(int i = 0; i < 256; i++) my_table.push_back(qRgb(i,i,i));
|
||||
for(int i = 0; i < 256; i++)
|
||||
my_table.push_back(qRgb(i,i,i));
|
||||
qtemp.setColorTable(my_table);
|
||||
}
|
||||
else
|
||||
@@ -113,11 +122,26 @@ inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true)
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
if(*p!=0 && (colorMap == uCvQtDepthBlackToWhite || colorMap == uCvQtDepthRedToBlue))
|
||||
{
|
||||
*p = 255-*p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRgb> my_table;
|
||||
for(int i = 0; i < 256; i++) my_table.push_back(qRgb(i,i,i));
|
||||
my_table.reserve(256);
|
||||
if(colorMap == uCvQtDepthRedToBlue || colorMap == uCvQtDepthBlueToRed)
|
||||
{
|
||||
my_table.push_back(qRgb(0,0,0));
|
||||
for(int i = 1; i < 256; i++)
|
||||
my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < 256; i++)
|
||||
my_table.push_back(qRgb(i,i,i));
|
||||
}
|
||||
qtemp.setColorTable(my_table);
|
||||
}
|
||||
else if(image.depth() == CV_16U && image.channels()==1)
|
||||
@@ -160,11 +184,26 @@ inline QImage uCvMat2QImage(const cv::Mat & image, bool isBgr = true)
|
||||
*p = 0;
|
||||
}
|
||||
}
|
||||
if(*p!=0 && (colorMap == uCvQtDepthBlackToWhite || colorMap == uCvQtDepthRedToBlue))
|
||||
{
|
||||
*p = 255-*p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVector<QRgb> my_table;
|
||||
for(int i = 0; i < 256; i++) my_table.push_back(qRgb(i,i,i));
|
||||
my_table.reserve(256);
|
||||
if(colorMap == uCvQtDepthRedToBlue || colorMap == uCvQtDepthBlueToRed)
|
||||
{
|
||||
my_table.push_back(qRgb(0,0,0));
|
||||
for(int i = 1; i < 256; i++)
|
||||
my_table.push_back(QColor::fromHsv(i, 255, 255, 255).rgb());
|
||||
}
|
||||
else
|
||||
{
|
||||
for(int i = 0; i < 256; i++)
|
||||
my_table.push_back(qRgb(i,i,i));
|
||||
}
|
||||
qtemp.setColorTable(my_table);
|
||||
}
|
||||
else if(!image.empty() && image.depth() != CV_8U)
|
||||
|
||||
@@ -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() &&
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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())
|
||||
{
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user