2012-06-24 17:19:34 +00:00
|
|
|
/*
|
2016-07-17 21:57:10 -04:00
|
|
|
Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
|
2014-08-11 17:00:55 +00:00
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
|
* Neither the name of the Universite de Sherbrooke nor the
|
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*/
|
2012-06-24 17:19:34 +00:00
|
|
|
|
|
|
|
|
#include "rtabmap/core/DBReader.h"
|
|
|
|
|
#include "rtabmap/core/DBDriver.h"
|
2012-12-11 18:05:05 +00:00
|
|
|
#include "DBDriverSqlite3.h"
|
2012-06-24 17:19:34 +00:00
|
|
|
|
2013-04-30 20:16:01 +00:00
|
|
|
#include <rtabmap/utilite/ULogger.h>
|
|
|
|
|
#include <rtabmap/utilite/UFile.h>
|
2015-04-17 18:30:12 -04:00
|
|
|
#include <rtabmap/utilite/UStl.h>
|
|
|
|
|
#include <rtabmap/utilite/UConversion.h>
|
2016-06-21 11:22:24 -04:00
|
|
|
#include <rtabmap/utilite/UEventsManager.h>
|
2012-06-24 17:19:34 +00:00
|
|
|
|
2013-02-04 16:38:00 +00:00
|
|
|
#include "rtabmap/core/CameraEvent.h"
|
2015-04-17 18:30:12 -04:00
|
|
|
#include "rtabmap/core/RtabmapEvent.h"
|
2013-12-11 00:12:44 +00:00
|
|
|
#include "rtabmap/core/OdometryEvent.h"
|
|
|
|
|
#include "rtabmap/core/util3d.h"
|
2015-01-23 11:17:42 -05:00
|
|
|
#include "rtabmap/core/Compression.h"
|
2012-12-11 18:05:05 +00:00
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
namespace rtabmap {
|
|
|
|
|
|
|
|
|
|
DBReader::DBReader(const std::string & databasePath,
|
2013-12-11 00:12:44 +00:00
|
|
|
float frameRate,
|
2014-02-28 22:11:36 +00:00
|
|
|
bool odometryIgnored,
|
2015-10-13 12:50:25 -04:00
|
|
|
bool ignoreGoalDelay,
|
2016-06-20 10:50:01 -04:00
|
|
|
bool goalsIgnored,
|
2016-06-21 11:22:24 -04:00
|
|
|
int startIndex,
|
2016-06-20 10:50:01 -04:00
|
|
|
int cameraIndex) :
|
2016-06-21 11:22:24 -04:00
|
|
|
Camera(frameRate),
|
2015-05-03 18:16:55 -04:00
|
|
|
_paths(uSplit(databasePath, ';')),
|
2013-12-11 00:12:44 +00:00
|
|
|
_odometryIgnored(odometryIgnored),
|
2015-04-27 02:43:06 -04:00
|
|
|
_ignoreGoalDelay(ignoreGoalDelay),
|
2015-10-13 12:50:25 -04:00
|
|
|
_goalsIgnored(goalsIgnored),
|
2016-06-21 11:22:24 -04:00
|
|
|
_startIndex(startIndex),
|
2016-06-20 10:50:01 -04:00
|
|
|
_cameraIndex(cameraIndex),
|
2012-06-24 17:19:34 +00:00
|
|
|
_dbDriver(0),
|
2015-06-26 18:21:32 -04:00
|
|
|
_currentId(_ids.end()),
|
2015-10-26 12:59:20 -04:00
|
|
|
_previousStamp(0),
|
2016-06-21 11:22:24 -04:00
|
|
|
_previousMapID(0),
|
|
|
|
|
_calibrated(false)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2015-05-03 18:16:55 -04:00
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
|
2015-05-03 18:16:55 -04:00
|
|
|
DBReader::DBReader(const std::list<std::string> & databasePaths,
|
|
|
|
|
float frameRate,
|
|
|
|
|
bool odometryIgnored,
|
2015-10-13 12:50:25 -04:00
|
|
|
bool ignoreGoalDelay,
|
2016-06-20 10:50:01 -04:00
|
|
|
bool goalsIgnored,
|
2016-06-21 11:22:24 -04:00
|
|
|
int startIndex,
|
2016-06-20 10:50:01 -04:00
|
|
|
int cameraIndex) :
|
2016-06-21 11:22:24 -04:00
|
|
|
Camera(frameRate),
|
2015-05-03 18:16:55 -04:00
|
|
|
_paths(databasePaths),
|
|
|
|
|
_odometryIgnored(odometryIgnored),
|
|
|
|
|
_ignoreGoalDelay(ignoreGoalDelay),
|
2015-10-13 12:50:25 -04:00
|
|
|
_goalsIgnored(goalsIgnored),
|
2016-06-21 11:22:24 -04:00
|
|
|
_startIndex(startIndex),
|
2016-06-20 10:50:01 -04:00
|
|
|
_cameraIndex(cameraIndex),
|
2015-05-03 18:16:55 -04:00
|
|
|
_dbDriver(0),
|
2015-06-26 18:21:32 -04:00
|
|
|
_currentId(_ids.end()),
|
2015-10-26 12:59:20 -04:00
|
|
|
_previousStamp(0),
|
2016-06-21 11:22:24 -04:00
|
|
|
_previousMapID(0),
|
|
|
|
|
_calibrated(false)
|
2015-05-03 18:16:55 -04:00
|
|
|
{
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DBReader::~DBReader()
|
|
|
|
|
{
|
|
|
|
|
if(_dbDriver)
|
|
|
|
|
{
|
|
|
|
|
_dbDriver->closeConnection();
|
|
|
|
|
delete _dbDriver;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
bool DBReader::init(
|
|
|
|
|
const std::string & calibrationFolder,
|
|
|
|
|
const std::string & cameraName)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
|
|
|
|
if(_dbDriver)
|
|
|
|
|
{
|
|
|
|
|
_dbDriver->closeConnection();
|
|
|
|
|
delete _dbDriver;
|
|
|
|
|
_dbDriver = 0;
|
|
|
|
|
}
|
|
|
|
|
_ids.clear();
|
|
|
|
|
_currentId=_ids.end();
|
2015-05-01 07:30:09 -04:00
|
|
|
_previousStamp = 0;
|
2015-10-26 12:59:20 -04:00
|
|
|
_previousMapID = 0;
|
2016-06-21 11:22:24 -04:00
|
|
|
_calibrated = false;
|
2012-06-24 17:19:34 +00:00
|
|
|
|
2015-05-03 18:16:55 -04:00
|
|
|
if(_paths.size() == 0)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2015-05-03 18:16:55 -04:00
|
|
|
UERROR("No database path set...");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string path = _paths.front();
|
|
|
|
|
if(!UFile::exists(path))
|
|
|
|
|
{
|
|
|
|
|
UERROR("Database path does not exist (%s)", path.c_str());
|
2012-06-24 17:19:34 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtabmap::ParametersMap parameters;
|
|
|
|
|
parameters.insert(rtabmap::ParametersPair(rtabmap::Parameters::kDbSqlite3InMemory(), "false"));
|
2012-12-11 18:05:05 +00:00
|
|
|
_dbDriver = new DBDriverSqlite3(parameters);
|
2012-06-24 17:19:34 +00:00
|
|
|
if(!_dbDriver)
|
|
|
|
|
{
|
|
|
|
|
UERROR("Driver doesn't exist.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2015-05-03 18:16:55 -04:00
|
|
|
if(!_dbDriver->openConnection(path))
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2015-05-03 18:16:55 -04:00
|
|
|
UERROR("Can't open database %s", path.c_str());
|
2012-06-24 17:19:34 +00:00
|
|
|
delete _dbDriver;
|
|
|
|
|
_dbDriver = 0;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbDriver->getAllNodeIds(_ids);
|
|
|
|
|
_currentId = _ids.begin();
|
2016-06-21 11:22:24 -04:00
|
|
|
if(_startIndex>0 && _ids.size())
|
2012-12-11 18:05:05 +00:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
std::set<int>::iterator iter = uIteratorAt(_ids, _startIndex);
|
2012-12-11 18:05:05 +00:00
|
|
|
if(iter == _ids.end())
|
|
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
UWARN("Start index is too high (%d), the last in database is %d. Starting from beginning...", _startIndex, _ids.size()-1);
|
2012-12-11 18:05:05 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_currentId = iter;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
if(_ids.size())
|
|
|
|
|
{
|
|
|
|
|
std::vector<CameraModel> models;
|
|
|
|
|
StereoCameraModel stereoModel;
|
|
|
|
|
if(_dbDriver->getCalibration(*_ids.begin(), models, stereoModel))
|
|
|
|
|
{
|
2016-12-02 13:43:44 -05:00
|
|
|
if(models.size())
|
2016-06-21 11:22:24 -04:00
|
|
|
{
|
2016-12-02 13:43:44 -05:00
|
|
|
if(models.at(0).isValidForProjection())
|
|
|
|
|
{
|
|
|
|
|
_calibrated = true;
|
|
|
|
|
}
|
|
|
|
|
else if(models.at(0).fx() && models.at(0).fy() && models.at(0).imageWidth() == 0)
|
|
|
|
|
{
|
|
|
|
|
// backward compatibility for databases not saving cx,cy and imageSize
|
|
|
|
|
SensorData data;
|
|
|
|
|
_dbDriver->getNodeData(*_ids.begin(), data, true, false, false, false);
|
|
|
|
|
cv::Mat rgb;
|
|
|
|
|
data.uncompressData(&rgb, 0); // this will update camera models if old format
|
|
|
|
|
if(data.cameraModels().size() && data.cameraModels().at(0).isValidForProjection())
|
|
|
|
|
{
|
|
|
|
|
_calibrated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
}
|
|
|
|
|
else if(stereoModel.isValidForProjection())
|
|
|
|
|
{
|
|
|
|
|
_calibrated = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-09-03 14:45:10 -04:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_calibrated = true; // database is empty, make sure calibration warning is not shown.
|
|
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
|
|
|
|
|
_timer.start();
|
|
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
bool DBReader::isCalibrated() const
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
return _calibrated;
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
std::string DBReader::getSerial() const
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
return "DBReader";
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
SensorData DBReader::captureImage(CameraInfo * info)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
SensorData data = this->getNextData(info);
|
|
|
|
|
if(data.id() == 0)
|
|
|
|
|
{
|
|
|
|
|
UINFO("no more images...");
|
|
|
|
|
while(_paths.size() > 1 && data.id() == 0)
|
|
|
|
|
{
|
|
|
|
|
_paths.pop_front();
|
|
|
|
|
UWARN("Loading next database \"%s\"...", _paths.front().c_str());
|
|
|
|
|
if(!this->init())
|
|
|
|
|
{
|
|
|
|
|
UERROR("Failed to initialize the next database \"%s\"", _paths.front().c_str());
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data = this->getNextData(info);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(data.id())
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2015-10-24 17:03:44 -04:00
|
|
|
std::string goalId;
|
2016-06-21 11:22:24 -04:00
|
|
|
double previousStamp = data.stamp();
|
2015-10-07 19:38:33 -04:00
|
|
|
if(previousStamp == 0)
|
|
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
data.setStamp(UTimer::now());
|
2015-10-07 19:38:33 -04:00
|
|
|
}
|
2015-10-24 17:03:44 -04:00
|
|
|
|
2015-10-13 12:50:25 -04:00
|
|
|
if(!_goalsIgnored &&
|
2016-06-21 11:22:24 -04:00
|
|
|
data.userDataRaw().type() == CV_8SC1 &&
|
|
|
|
|
data.userDataRaw().cols >= 7 && // including null str ending
|
|
|
|
|
data.userDataRaw().rows == 1 &&
|
|
|
|
|
memcmp(data.userDataRaw().data, "GOAL:", 5) == 0)
|
2015-04-17 18:30:12 -04:00
|
|
|
{
|
|
|
|
|
//GOAL format detected, remove it from the user data and send it as goal event
|
2016-06-21 11:22:24 -04:00
|
|
|
std::string goalStr = (const char *)data.userDataRaw().data;
|
2015-04-17 18:30:12 -04:00
|
|
|
if(!goalStr.empty())
|
|
|
|
|
{
|
|
|
|
|
std::list<std::string> strs = uSplit(goalStr, ':');
|
|
|
|
|
if(strs.size() == 2)
|
|
|
|
|
{
|
2015-10-24 17:03:44 -04:00
|
|
|
goalId = *strs.rbegin();
|
2016-06-21 11:22:24 -04:00
|
|
|
data.setUserData(cv::Mat());
|
2014-12-14 16:42:10 -05:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
double delay = 0.0;
|
|
|
|
|
if(!_ignoreGoalDelay && _currentId != _ids.end())
|
|
|
|
|
{
|
|
|
|
|
// get stamp for the next signature to compute the delay
|
|
|
|
|
// that was used originally for planning
|
|
|
|
|
int weight;
|
|
|
|
|
std::string label;
|
|
|
|
|
double stamp;
|
|
|
|
|
int mapId;
|
|
|
|
|
Transform localTransform, pose, groundTruth;
|
|
|
|
|
_dbDriver->getNodeInfo(*_currentId, pose, mapId, weight, label, stamp, groundTruth);
|
|
|
|
|
if(previousStamp && stamp && stamp > previousStamp)
|
|
|
|
|
{
|
|
|
|
|
delay = stamp - previousStamp;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-24 17:03:44 -04:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
if(delay > 0.0)
|
|
|
|
|
{
|
|
|
|
|
UWARN("Goal \"%s\" detected, posting it! Waiting %f seconds before sending next data...",
|
|
|
|
|
goalId.c_str(), delay);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UWARN("Goal \"%s\" detected, posting it!", goalId.c_str());
|
|
|
|
|
}
|
2015-10-24 17:03:44 -04:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
if(uIsInteger(goalId))
|
|
|
|
|
{
|
|
|
|
|
UEventsManager::post(new RtabmapEventCmd(RtabmapEventCmd::kCmdGoal, atoi(goalId.c_str())));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UEventsManager::post(new RtabmapEventCmd(RtabmapEventCmd::kCmdGoal, goalId));
|
|
|
|
|
}
|
2015-04-17 18:30:12 -04:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
if(delay > 0.0)
|
|
|
|
|
{
|
|
|
|
|
uSleep(delay*1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-05-03 18:16:55 -04:00
|
|
|
}
|
|
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
return data;
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
SensorData DBReader::getNextData(CameraInfo * info)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
SensorData data;
|
2012-06-24 17:19:34 +00:00
|
|
|
if(_dbDriver)
|
|
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
if(_currentId != _ids.end())
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2013-12-11 00:12:44 +00:00
|
|
|
int mapId;
|
2015-05-29 14:46:48 -04:00
|
|
|
_dbDriver->getNodeData(*_currentId, data);
|
2015-03-25 13:31:12 -04:00
|
|
|
|
|
|
|
|
// info
|
2015-05-29 14:46:48 -04:00
|
|
|
Transform pose;
|
2015-03-25 13:31:12 -04:00
|
|
|
int weight;
|
|
|
|
|
std::string label;
|
|
|
|
|
double stamp;
|
2016-01-07 19:39:21 -05:00
|
|
|
Transform groundTruth;
|
|
|
|
|
_dbDriver->getNodeInfo(*_currentId, pose, mapId, weight, label, stamp, groundTruth);
|
2015-03-25 13:31:12 -04:00
|
|
|
|
2015-05-29 14:46:48 -04:00
|
|
|
cv::Mat infMatrix = cv::Mat::eye(6,6,CV_64FC1);
|
2014-12-14 16:42:10 -05:00
|
|
|
if(!_odometryIgnored)
|
|
|
|
|
{
|
|
|
|
|
std::map<int, Link> links;
|
|
|
|
|
_dbDriver->loadLinks(*_currentId, links, Link::kNeighbor);
|
2017-01-29 18:24:10 -05:00
|
|
|
if(links.size() && links.begin()->first < *_currentId)
|
2014-12-14 16:42:10 -05:00
|
|
|
{
|
|
|
|
|
// assume the first is the backward neighbor, take its variance
|
2015-05-29 14:46:48 -04:00
|
|
|
infMatrix = links.begin()->second.infMatrix();
|
2014-12-14 16:42:10 -05:00
|
|
|
}
|
2017-01-29 18:24:10 -05:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// first node, set high variance to make rtabmap trigger a new map
|
|
|
|
|
infMatrix /= 9999.0;
|
|
|
|
|
}
|
2014-12-14 16:42:10 -05:00
|
|
|
}
|
2015-03-25 13:31:12 -04:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pose.setNull();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-14 16:42:10 -05:00
|
|
|
int seq = *_currentId;
|
2012-06-24 17:19:34 +00:00
|
|
|
++_currentId;
|
2015-05-29 14:46:48 -04:00
|
|
|
if(data.imageCompressed().empty())
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
2013-12-11 00:12:44 +00:00
|
|
|
UWARN("No image loaded from the database for id=%d!", *_currentId);
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
2013-12-11 00:12:44 +00:00
|
|
|
|
2015-05-01 07:30:09 -04:00
|
|
|
// Frame rate
|
2016-06-21 11:22:24 -04:00
|
|
|
if(this->getImageRate() < 0.0f)
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
|
|
|
|
if(stamp == 0)
|
|
|
|
|
{
|
|
|
|
|
UERROR("The option to use database stamps is set (framerate<0), but there are no stamps saved in the database! Aborting...");
|
2016-06-21 11:22:24 -04:00
|
|
|
return data;
|
2015-05-01 07:30:09 -04:00
|
|
|
}
|
2015-10-26 12:59:20 -04:00
|
|
|
else if(_previousMapID == mapId && _previousStamp > 0)
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
|
|
|
|
int sleepTime = 1000.0*(stamp-_previousStamp) - 1000.0*_timer.getElapsedTime();
|
2015-10-26 12:59:20 -04:00
|
|
|
if(sleepTime > 10000)
|
|
|
|
|
{
|
|
|
|
|
UWARN("Detected long delay (%d sec, stamps = %f vs %f). Waiting a maximum of 10 seconds.",
|
|
|
|
|
sleepTime/1000, _previousStamp, stamp);
|
|
|
|
|
sleepTime = 10000;
|
|
|
|
|
}
|
2015-05-01 07:30:09 -04:00
|
|
|
if(sleepTime > 2)
|
|
|
|
|
{
|
|
|
|
|
uSleep(sleepTime-2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add precision at the cost of a small overhead
|
|
|
|
|
while(_timer.getElapsedTime() < (stamp-_previousStamp)-0.000001)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double slept = _timer.getElapsedTime();
|
|
|
|
|
_timer.start();
|
|
|
|
|
UDEBUG("slept=%fs vs target=%fs", slept, stamp-_previousStamp);
|
|
|
|
|
}
|
|
|
|
|
_previousStamp = stamp;
|
2015-10-26 12:59:20 -04:00
|
|
|
_previousMapID = mapId;
|
2015-05-01 07:30:09 -04:00
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
|
|
|
|
|
data.uncompressData();
|
|
|
|
|
if(data.cameraModels().size() > 1 &&
|
|
|
|
|
_cameraIndex >= 0)
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
if(_cameraIndex < (int)data.cameraModels().size())
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
// select one camera
|
|
|
|
|
int subImageWidth = data.imageRaw().cols/data.cameraModels().size();
|
|
|
|
|
UASSERT(!data.imageRaw().empty() &&
|
|
|
|
|
data.imageRaw().cols % data.cameraModels().size() == 0 &&
|
|
|
|
|
_cameraIndex*subImageWidth < data.imageRaw().cols);
|
|
|
|
|
data.setImageRaw(
|
|
|
|
|
cv::Mat(data.imageRaw(),
|
|
|
|
|
cv::Rect(_cameraIndex*subImageWidth, 0, subImageWidth, data.imageRaw().rows)).clone());
|
|
|
|
|
|
|
|
|
|
if(!data.depthOrRightRaw().empty())
|
|
|
|
|
{
|
|
|
|
|
UASSERT(data.depthOrRightRaw().cols % data.cameraModels().size() == 0 &&
|
|
|
|
|
subImageWidth == data.depthOrRightRaw().cols/(int)data.cameraModels().size() &&
|
|
|
|
|
_cameraIndex*subImageWidth < data.depthOrRightRaw().cols);
|
|
|
|
|
data.setDepthOrRightRaw(
|
|
|
|
|
cv::Mat(data.depthOrRightRaw(),
|
|
|
|
|
cv::Rect(_cameraIndex*subImageWidth, 0, subImageWidth, data.depthOrRightRaw().rows)).clone());
|
|
|
|
|
}
|
|
|
|
|
CameraModel model = data.cameraModels().at(_cameraIndex);
|
|
|
|
|
data.setCameraModel(model);
|
2015-05-01 07:30:09 -04:00
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
else
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
UWARN("DBReader: Camera index %d doesn't exist! Camera models = %d.", _cameraIndex, (int)data.cameraModels().size());
|
2015-05-01 07:30:09 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
data.setId(seq);
|
|
|
|
|
data.setStamp(stamp);
|
|
|
|
|
data.setGroundTruth(groundTruth);
|
|
|
|
|
UDEBUG("Laser=%d RGB/Left=%d Depth/Right=%d, UserData=%d",
|
|
|
|
|
data.laserScanRaw().empty()?0:1,
|
|
|
|
|
data.imageRaw().empty()?0:1,
|
|
|
|
|
data.depthOrRightRaw().empty()?0:1,
|
|
|
|
|
data.userDataRaw().empty()?0:1);
|
2015-05-01 07:30:09 -04:00
|
|
|
|
2016-06-21 11:22:24 -04:00
|
|
|
if(!_odometryIgnored)
|
2015-05-01 07:30:09 -04:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
if(pose.isNull())
|
2016-06-20 10:50:01 -04:00
|
|
|
{
|
2016-06-21 11:22:24 -04:00
|
|
|
UWARN("Reading the database: odometry is null! "
|
|
|
|
|
"Please set \"Ignore odometry = true\" if there is "
|
|
|
|
|
"no odometry in the database.");
|
|
|
|
|
}
|
|
|
|
|
if(info)
|
|
|
|
|
{
|
|
|
|
|
info->odomPose = pose;
|
|
|
|
|
info->odomCovariance = infMatrix.inv();
|
2016-06-20 10:50:01 -04:00
|
|
|
}
|
2015-05-01 07:30:09 -04:00
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
UERROR("Not initialized...");
|
|
|
|
|
}
|
2016-06-21 11:22:24 -04:00
|
|
|
return data;
|
2012-06-24 17:19:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} /* namespace rtabmap */
|