53 bool intermediateNodesIgnored,
54 bool landmarksIgnored,
60 _paths(
uSplit(databasePath,
';')),
61 _odometryIgnored(odometryIgnored),
62 _ignoreGoalDelay(ignoreGoalDelay),
63 _goalsIgnored(goalsIgnored),
66 _cameraIndex(cameraIndex),
67 _intermediateNodesIgnored(intermediateNodesIgnored),
68 _landmarksIgnored(landmarksIgnored),
69 _featuresIgnored(featuresIgnored),
70 _priorsIgnored(priorsIgnored),
71 _startMapId(startMapId),
72 _stopMapId(stopMapId),
74 _currentId(_ids.
end()),
99 bool intermediateNodesIgnored,
100 bool landmarksIgnored,
101 bool featuresIgnored,
104 bool priorsIgnored) :
106 _paths(databasePaths),
107 _odometryIgnored(odometryIgnored),
108 _ignoreGoalDelay(ignoreGoalDelay),
109 _goalsIgnored(goalsIgnored),
112 _cameraIndex(cameraIndex),
113 _intermediateNodesIgnored(intermediateNodesIgnored),
114 _landmarksIgnored(landmarksIgnored),
115 _featuresIgnored(featuresIgnored),
116 _priorsIgnored(priorsIgnored),
117 _startMapId(startMapId),
118 _stopMapId(stopMapId),
120 _currentId(_ids.
end()),
147 const std::string & calibrationFolder,
148 const std::string & cameraName)
166 UERROR(
"No database path set...");
173 UERROR(
"Database path does not exist (%s)",
path.c_str());
182 UERROR(
"Driver doesn't exist.");
187 UERROR(
"Can't open database %s",
path.c_str());
200 UWARN(
"Start index is too high (%d), the last ID in database is %d. Starting from beginning...",
_startId, *
_ids.rbegin());
210 std::vector<CameraModel> models;
211 std::vector<StereoCameraModel> stereoModels;
216 if(models.at(0).isValidForProjection())
220 else if(models.at(0).fx() && models.at(0).fy() && models.at(0).imageWidth() == 0)
226 data.uncompressData(&rgb, 0);
227 if(
data.cameraModels().size() &&
data.cameraModels().at(0).isValidForProjection())
233 else if(stereoModels.size() && stereoModels.at(0).isValidForProjection())
241 if(
s->sensorData().imageCompressed().empty() &&
242 s->getWords().empty() &&
243 !
s->sensorData().laserScanCompressed().empty())
273 UERROR(
"DBReader only provides pose when capturing data, it cannot provide asynchronous pose.");
282 UINFO(
"Last ID %d has been reached! Ignoring",
_stopId);
287 UINFO(
"no more images...");
291 UWARN(
"Loading next database \"%s\"...",
_paths.front().c_str());
294 UERROR(
"Failed to initialize the next database \"%s\"",
_paths.front().c_str());
307 double previousStamp =
data.stamp();
308 if(previousStamp == 0)
314 data.userDataRaw().type() == CV_8SC1 &&
315 data.userDataRaw().cols >= 7 &&
316 data.userDataRaw().rows == 1 &&
317 memcmp(
data.userDataRaw().data,
"GOAL:", 5) == 0)
320 std::string goalStr = (
const char *)
data.userDataRaw().data;
323 std::list<std::string> strs =
uSplit(goalStr,
':');
326 goalId = *strs.rbegin();
327 data.setUserData(cv::Mat());
338 Transform localTransform, pose, groundTruth;
343 if(previousStamp && stamp && stamp > previousStamp)
345 delay = stamp - previousStamp;
351 UWARN(
"Goal \"%s\" detected, posting it! Waiting %f seconds before sending next data...",
352 goalId.c_str(), delay);
356 UWARN(
"Goal \"%s\" detected, posting it!", goalId.c_str());
386 std::list<int> signIds;
388 std::list<Signature *> signatures;
390 if(signatures.empty())
399 UDEBUG(
"Ignoring node %d (intermediate nodes ignored)",
s->id());
413 data =
s->sensorData();
418 cv::Mat globalPoseCov;
420 std::multimap<int, Link> priorLinks;
424 if( priorLinks.size() &&
425 !priorLinks.begin()->second.transform().isNull() &&
426 priorLinks.begin()->second.infMatrix().cols == 6 &&
427 priorLinks.begin()->second.infMatrix().rows == 6)
429 globalPose = priorLinks.begin()->second.transform();
430 globalPoseCov = priorLinks.begin()->second.infMatrix().inv();
431 if(
data.gps().stamp() != 0.0 &&
432 globalPoseCov.at<
double>(3,3)>=9999 &&
433 globalPoseCov.at<
double>(4,4)>=9999 &&
434 globalPoseCov.at<
double>(5,5)>=9999)
443 std::multimap<int, Link> gravityLinks;
445 if( gravityLinks.size() &&
446 !gravityLinks.begin()->second.transform().isNull() &&
447 gravityLinks.begin()->second.infMatrix().cols == 6 &&
448 gravityLinks.begin()->second.infMatrix().rows == 6)
450 gravityTransform = gravityLinks.begin()->second.transform();
456 std::multimap<int, Link> landmarkLinks;
458 for(std::multimap<int, Link>::iterator
iter=landmarkLinks.begin();
iter!=landmarkLinks.end(); ++
iter)
460 cv::Mat landmarkSize =
iter->second.uncompressUserDataConst();
461 landmarks.insert(std::make_pair(-
iter->first,
463 !landmarkSize.empty() && landmarkSize.type() == CV_32FC1 && landmarkSize.total()==1?landmarkSize.at<
float>(0,0):0.0f,
464 iter->second.transform(),
465 iter->second.infMatrix().inv())));
469 cv::Mat infMatrix = cv::Mat::eye(6,6,CV_64FC1);
472 std::multimap<int, Link> links;
474 if(links.size() && links.begin()->first < *
_currentId)
477 infMatrix = links.begin()->second.infMatrix();
486 UDEBUG(
"First node of map %d, variance set to 9999",
s->mapId());
495 infMatrix = links.begin()->second.infMatrix();
522 if(
s->getStamp() == 0)
524 UERROR(
"The option to use database stamps is set (framerate<0), but there are no stamps saved in the database! Aborting...");
532 double stamp =
s->getStamp();
533 if(sleepTime > 10000)
535 UWARN(
"Detected long delay (%d sec, stamps = %f vs %f). Waiting a maximum of 10 seconds.",
559 data.uncompressData();
560 if(
data.cameraModels().size() > 1 &&
566 int subImageWidth =
data.imageRaw().cols/
data.cameraModels().size();
569 data.imageRaw().cols %
data.cameraModels().size() == 0 &&
571 image= cv::Mat(
data.imageRaw(),
572 cv::Rect(
_cameraIndex*subImageWidth, 0, subImageWidth,
data.imageRaw().rows)).clone();
575 if(!
data.depthOrRightRaw().empty())
577 UASSERT(
data.depthOrRightRaw().cols %
data.cameraModels().size() == 0 &&
578 subImageWidth ==
data.depthOrRightRaw().cols/(
int)
data.cameraModels().size() &&
580 depth = cv::Mat(
data.depthOrRightRaw(),
581 cv::Rect(
_cameraIndex*subImageWidth, 0, subImageWidth,
data.depthOrRightRaw().rows)).clone();
587 UWARN(
"DBReader: Camera index %d doesn't exist! Camera models = %d.",
_cameraIndex, (
int)
data.cameraModels().size());
591 data.setStamp(
s->getStamp());
592 data.setGroundTruth(
s->getGroundTruthPose());
595 data.setGlobalPose(globalPose, globalPoseCov);
597 if(!gravityTransform.
isNull())
601 cv::Vec4d(
q.x(),
q.y(),
q.z(),
q.w()), cv::Mat::eye(3,3,CV_64FC1),
602 cv::Vec3d(), cv::Mat(),
603 cv::Vec3d(), cv::Mat(),
606 data.setLandmarks(landmarks);
608 UDEBUG(
"Laser=%d RGB/Left=%d Depth/Right=%d, Grid=%d, UserData=%d, GlobalPose=%d, GPS=%d, IMU=%d",
609 data.laserScanRaw().isEmpty()?0:1,
610 data.imageRaw().empty()?0:1,
611 data.depthOrRightRaw().empty()?0:1,
612 data.gridCellSize()==0.0f?0:1,
613 data.userDataRaw().empty()?0:1,
615 data.gps().stamp()!=0.0?1:0,
616 gravityTransform.
isNull()?0:1);
618 cv::Mat descriptors =
s->getWordsDescriptors().clone();
619 const std::vector<cv::KeyPoint> & keypoints =
s->getWordsKpts();
620 const std::vector<cv::Point3f> & keypoints3D =
s->getWords3();
622 !keypoints.empty() &&
623 (keypoints3D.empty() || keypoints.size() == keypoints3D.size()) &&
624 (descriptors.empty() || (
int)keypoints.size() == descriptors.rows))
626 data.setFeatures(keypoints, keypoints3D, descriptors);
628 else if(!
_featuresIgnored && !keypoints.empty() && (!keypoints3D.empty() || !descriptors.empty()))
630 UERROR(
"Missing feature data, features won't be published.");
633 if(
data.imageCompressed().empty() &&
s->getWeight()>=0 && keypoints.empty())
635 UWARN(
"No image loaded from the database for id=%d!",
seq);
642 UWARN(
"Reading the database: odometry is null! "
643 "Please set \"Ignore odometry = true\" if there is "
644 "no odometry in the database.");
648 info->odomPose = pose;
649 info->odomCovariance = infMatrix.inv();
650 info->odomVelocity =
s->getVelocity();
651 UDEBUG(
"odom variance = %f/%f",
info->odomCovariance.at<
double>(0,0),
info->odomCovariance.at<
double>(5,5));
660 UERROR(
"Not initialized...");