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

@@ -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;
};
}

View File

@@ -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)