ImageView: added option to set maximum range for depth colormap

This commit is contained in:
matlabbe
2022-03-03 18:01:04 -05:00
parent b9c7182a08
commit 1e82fd3110
3 changed files with 66 additions and 22 deletions

View File

@@ -170,6 +170,7 @@ ImageView::ImageView(QWidget * parent) :
_defaultFeatureColor(Qt::yellow),
_defaultMatchingFeatureColor(Qt::magenta),
_defaultMatchingLineColor(Qt::cyan),
_depthColorMapRange(0),
_imageItem(0),
_imageDepthItem(0)
{
@@ -251,11 +252,13 @@ ImageView::ImageView(QWidget * parent) :
_colorMapBlueToRed = colorMap->addAction(tr("Blue to red"));
_colorMapBlueToRed->setCheckable(true);
_colorMapBlueToRed->setChecked(false);
_colorMapRange = colorMap->addAction(tr("Max Range..."));
group = new QActionGroup(this);
group->addAction(_colorMapWhiteToBlack);
group->addAction(_colorMapBlackToWhite);
group->addAction(_colorMapRedToBlue);
group->addAction(_colorMapBlueToRed);
group->addAction(_colorMapRange);
_saveImage = _menu->addAction(tr("Save picture..."));
_saveImage->setEnabled(false);
@@ -286,6 +289,7 @@ void ImageView::saveSettings(QSettings & settings, const QString & group) const
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);
settings.setValue("colormap_range", this->getDepthColorMapRange());
if(!group.isEmpty())
{
settings.endGroup();
@@ -316,6 +320,7 @@ void ImageView::loadSettings(QSettings & settings, const QString & group)
_colorMapBlackToWhite->setChecked(colorMap==1);
_colorMapRedToBlue->setChecked(colorMap==2);
_colorMapBlueToRed->setChecked(colorMap==3);
this->setDepthColorMapRange(settings.value("colormap_range", this->getDepthColorMapRange()).toFloat());
if(!group.isEmpty())
{
settings.endGroup();
@@ -379,6 +384,11 @@ const QColor & ImageView::getBackgroundColor() const
return _graphicsView->backgroundBrush().color();
}
float ImageView::getDepthColorMapRange() const
{
return _depthColorMapRange;
}
uCvQtDepthColorMap ImageView::getDepthColorMap() const
{
uCvQtDepthColorMap colorMap = uCvQtDepthWhiteToBlack;
@@ -676,6 +686,12 @@ void ImageView::setBackgroundColor(const QColor & color)
}
}
void ImageView::setDepthColorMapRange(float value)
{
_depthColorMapRange = value;
}
void ImageView::computeScaleOffsets(const QRect & targetRect, float & scale, float & offsetX, float & offsetY) const
{
scale = 1.0f;
@@ -950,6 +966,16 @@ void ImageView::contextMenuEvent(QContextMenuEvent * e)
this->setImageDepth(_imageDepthCv);
Q_EMIT configChanged();
}
else if(action == _colorMapRange)
{
bool ok = false;
double value = QInputDialog::getDouble(this, tr("Set depth colormap max range"), tr("Range (m), 0=no limit"), _depthColorMapRange, 0, 9999, 1, &ok);
if(ok)
{
this->setDepthColorMapRange(value);
Q_EMIT configChanged();
}
}
else if(action == _setAlpha)
{
bool ok = false;
@@ -1126,7 +1152,7 @@ void ImageView::setImage(const QImage & image)
void ImageView::setImageDepth(const cv::Mat & imageDepth)
{
_imageDepthCv = imageDepth;
setImageDepth(uCvMat2QImage(_imageDepthCv, true, getDepthColorMap()));
setImageDepth(uCvMat2QImage(_imageDepthCv, true, getDepthColorMap(), 0.0f, _depthColorMapRange));
}
void ImageView::setImageDepth(const QImage & imageDepth)