ImageView: Fixed feature's depth value when depth image is not the same size as the RGB image

This commit is contained in:
matlabbe
2016-10-17 13:30:35 -04:00
parent 07ff1a7717
commit 1853cfde9b
3 changed files with 54 additions and 11 deletions
+5
View File
@@ -1972,6 +1972,7 @@ CameraRealSense::CameraRealSense(int device, int presetRGB, int presetDepth, flo
presetRGB_(presetRGB), presetRGB_(presetRGB),
presetDepth_(presetDepth) presetDepth_(presetDepth)
{ {
UDEBUG("");
} }
CameraRealSense::~CameraRealSense() CameraRealSense::~CameraRealSense()
@@ -1986,17 +1987,21 @@ CameraRealSense::~CameraRealSense()
bool CameraRealSense::init(const std::string & calibrationFolder, const std::string & cameraName) bool CameraRealSense::init(const std::string & calibrationFolder, const std::string & cameraName)
{ {
UDEBUG("");
#ifdef RTABMAP_REALSENSE #ifdef RTABMAP_REALSENSE
if (ctx_ == 0) if (ctx_ == 0)
{ {
ctx_ = new rs::context(); ctx_ = new rs::context();
} }
UDEBUG("");
if (ctx_->get_device_count() == 0) if (ctx_->get_device_count() == 0)
{ {
UERROR("No RealSense device detected!"); UERROR("No RealSense device detected!");
return false; return false;
} }
UDEBUG("");
dev_ = ctx_->get_device(deviceId_); dev_ = ctx_->get_device(deviceId_);
if (dev_ == 0) if (dev_ == 0)
{ {
+36 -2
View File
@@ -654,9 +654,26 @@ void ImageView::setFeatures(const std::multimap<int, cv::KeyPoint> & refWords, c
qDeleteAll(_features); qDeleteAll(_features);
_features.clear(); _features.clear();
float xRatio = 0;
float yRatio = 0;
if (this->sceneRect().isValid() && !depth.empty() && int(this->sceneRect().height()) % depth.rows == 0 && int(this->sceneRect().width()) % depth.cols == 0)
{
UDEBUG("depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows, this->sceneRect().width(), this->sceneRect().height());
xRatio = float(depth.cols)/float(this->sceneRect().width());
yRatio = float(depth.rows)/float(this->sceneRect().height());
UDEBUG("xRatio=%f yRatio=%f", xRatio, yRatio);
}
for(std::multimap<int, cv::KeyPoint>::const_iterator iter = refWords.begin(); iter != refWords.end(); ++iter ) for(std::multimap<int, cv::KeyPoint>::const_iterator iter = refWords.begin(); iter != refWords.end(); ++iter )
{ {
addFeature(iter->first, iter->second, depth.empty()?0:util2d::getDepth(depth, iter->second.pt.x, iter->second.pt.y, false), color); if (xRatio > 0 && yRatio > 0)
{
addFeature(iter->first, iter->second, util2d::getDepth(depth, iter->second.pt.x*xRatio, iter->second.pt.y*yRatio, false), color);
}
else
{
addFeature(iter->first, iter->second, 0, color);
}
} }
if(!_graphicsView->isVisible()) if(!_graphicsView->isVisible())
@@ -670,9 +687,26 @@ void ImageView::setFeatures(const std::vector<cv::KeyPoint> & features, const cv
qDeleteAll(_features); qDeleteAll(_features);
_features.clear(); _features.clear();
float xRatio = 0;
float yRatio = 0;
if (this->sceneRect().isValid() && !depth.empty() && int(this->sceneRect().height()) % depth.rows == 0 && int(this->sceneRect().width()) % depth.cols == 0)
{
UDEBUG("depth=%dx%d sceneRect=%fx%f", depth.cols, depth.rows, this->sceneRect().width(), this->sceneRect().height());
xRatio = float(depth.cols) / float(this->sceneRect().width());
yRatio = float(depth.rows) / float(this->sceneRect().height());
UDEBUG("xRatio=%f yRatio=%f", xRatio, yRatio);
}
for(unsigned int i = 0; i< features.size(); ++i ) for(unsigned int i = 0; i< features.size(); ++i )
{ {
addFeature(i, features[i], depth.empty()?0:util2d::getDepth(depth, features[i].pt.x, features[i].pt.y, false), color); if(xRatio > 0 && yRatio > 0)
{
addFeature(i, features[i], util2d::getDepth(depth, features[i].pt.x*xRatio, features[i].pt.y*yRatio, false), color);
}
else
{
addFeature(i, features[i], 0, color);
}
} }
if(!_graphicsView->isVisible()) if(!_graphicsView->isVisible())
+4
View File
@@ -1946,6 +1946,8 @@ void PreferencesDialog::writeSettings(const QString & filePath)
} }
for(ParametersMap::iterator iter = _modifiedParameters.begin(); iter!=_modifiedParameters.end(); ++iter) for(ParametersMap::iterator iter = _modifiedParameters.begin(); iter!=_modifiedParameters.end(); ++iter)
{
if (_parameters.at(iter->first).compare(iter->second) != 0)
{ {
bool different = true; bool different = true;
if (Parameters::getType(iter->first).compare("double") == 0 || if (Parameters::getType(iter->first).compare("double") == 0 ||
@@ -1961,6 +1963,7 @@ void PreferencesDialog::writeSettings(const QString & filePath)
UINFO("modified %s = %s->%s", iter->first.c_str(), _parameters.at(iter->first).c_str(), iter->second.c_str()); UINFO("modified %s = %s->%s", iter->first.c_str(), _parameters.at(iter->first).c_str(), iter->second.c_str());
} }
} }
}
uInsert(_parameters, _modifiedParameters); // update cached parameters uInsert(_parameters, _modifiedParameters); // update cached parameters
_modifiedParameters.clear(); _modifiedParameters.clear();
@@ -4164,6 +4167,7 @@ int PreferencesDialog::getSourceScanNormalsK() const
Camera * PreferencesDialog::createCamera(bool useRawImages, bool useColor) Camera * PreferencesDialog::createCamera(bool useRawImages, bool useColor)
{ {
UDEBUG("");
Src driver = this->getSourceDriver(); Src driver = this->getSourceDriver();
Camera * camera = 0; Camera * camera = 0;
if(driver == PreferencesDialog::kSrcOpenNI_PCL) if(driver == PreferencesDialog::kSrcOpenNI_PCL)