Osmap  1
Osmap documentation
ORB_SLAM2::Osmap Class Reference

This is a class for a singleton attached to ORB-SLAM2's map. More...

#include <Osmap.h>

Collaboration diagram for ORB_SLAM2::Osmap:
[legend]

Public Types

enum  Options {
  FEATURES_FILE_DELIMITED, FEATURES_FILE_NOT_DELIMITED, NO_MAPPOINTS_FILE, NO_KEYFRAMES_FILE,
  NO_FEATURES_FILE, NO_FEATURES_DESCRIPTORS, ONLY_MAPPOINTS_FEATURES, NO_LOOPS,
  K_IN_KEYFRAME, NO_DEPURATION, NO_SET_BAD, NO_APPEND_FOUND_MAPPOINTS,
  OPTIONS_SIZE
}
 All the options available. More...
 

Public Member Functions

void clearVectors ()
 Clear temporary vectors. More...
 
int countFeatures ()
 Count the number of features in vectorKeyFrames. More...
 
void depurate ()
 Irons keyframes and mappoints sets in map, before save. More...
 
void deserialize (const SerializedK &, Mat &k)
 Reconstruct the intrinsic camera matrix K from protocol buffer message. More...
 
void deserialize (const SerializedKArray &serializedKArray, vector< Mat *> &vK)
 Reconstruct an array of camera calibration matrix K. More...
 
void deserialize (const SerializedDescriptor &, Mat &)
 Reconstruct a descriptor, an 1x32 uchar Mat (256 bits). More...
 
void deserialize (const SerializedPose &, Mat &)
 Reconstruct a 4x4 float Mat representing a pose in homogeneous coordinates. More...
 
void deserialize (const SerializedPosition &, Mat &)
 Reconstructs 3D mappoint position in a 3x1 float Mat. More...
 
void deserialize (const SerializedKeypoint &, KeyPoint &)
 Reconstructs a KeyPoint. More...
 
OsmapMapPointdeserialize (const SerializedMappoint &serializedMappoint)
 Creates and fills a MapPoint from optional message fields. More...
 
int deserialize (const SerializedMappointArray &, vector< OsmapMapPoint *> &)
 Retrieves MapPoints from an array, and append them to the map. More...
 
OsmapKeyFramedeserialize (const SerializedKeyframe &)
 Reconstructs a KeyFrame from optional fields. More...
 
int deserialize (const SerializedKeyframeArray &, vector< OsmapKeyFrame *> &)
 Retrieves MapPoints from an array, and append them to the map. More...
 
OsmapKeyFramedeserialize (const SerializedKeyframeFeatures &)
 Retrieves all features belonging to one keyframe. More...
 
int deserialize (const SerializedKeyframeFeaturesArray &)
 Retrieves all keyframe's features from the specified serialization object to vectorKeyframe. More...
 
int featuresLoad (string filename)
 Load the content of a "map.features" file and applies it to vectorKeyFrames. More...
 
int featuresSave (string filename)
 Save KeyFrane's features of vectorKeyFrames to file, usually "map.features". More...
 
OsmapKeyFramegetKeyFrame (unsigned int id)
 Looks for a KeyFrame id in the map. More...
 
void getKeyFramesFromMap ()
 Populate vectorKeyFrames with MapPoints from Map.mspKeyFrames. More...
 
MapPoint * getMapPoint (unsigned int id)
 Looks for a mappoint by its id in the map. More...
 
void getMapPointsFromMap ()
 Populate vectorMapPoints with MapPoints from Map.mspMapPoints. More...
 
void getVectorKFromKeyframes ()
 Traverse map's keyframes looking for different K matrices, and stores them into vectorK. More...
 
int KeyFramesLoad (string filename)
 Load the content of a "map.keyframes" file to vectorKeyFrames. More...
 
int KeyFramesSave (string filename)
 Save the content of vectorKeyFrames to file like "map.keyframes". More...
 
void log ()
 
template<typename Head , typename... Args>
void log (const Head &head, const Args &... args)
 
void mapLoad (string yamlFilename, bool noSetBad=false, bool pauseThreads=true)
 Loads the map from a set of files in the folder whose name is provided as an argument. More...
 
int MapPointsLoad (string filename)
 Load the content of a "map.mappoints" file to vectorMapPoints. More...
 
int MapPointsSave (string filename)
 Save the content of vectorMapPoints to file like "map.mappoints". More...
 
void mapSave (string basefilename, bool pauseThreads=true)
 Saves the map to a set of files in the actual directory, with the extensionless name provided as the only argument and different extensions for each file. More...
 
 Osmap (System &_system)
 Only constructor, the only way to set the orb-slam2 map. More...
 
void parsePath (const string &path, string *filename=NULL, string *pathDirectory=NULL)
 Utility for separating path and filename from a full path. More...
 
bool readDelimitedFrom (google::protobuf::io::ZeroCopyInputStream *rawInput, google::protobuf::MessageLite *message)
 Reads a message to a vector file. More...
 
void rebuild (bool noSetBad=false)
 Rebuilding takes place right after loading a map from files, before the map is copied to ORB-SLAM2' sets. More...
 
void serialize (const Mat &k, SerializedK *serializedK)
 Serialize provided intrinsic camera matrix K to the protocol buffer message. More...
 
void serialize (const vector< Mat *> &vK, SerializedKArray &serializedKArray)
 Serialize an array of camera calibration matrix K. More...
 
void serialize (const Mat &, SerializedDescriptor *)
 Serializes a descriptor, an 1x32 uchar Mat (256 bits). More...
 
void serialize (const Mat &, SerializedPose *)
 Serialize a 4x4 float Mat representing a pose in homogeneous coordinates. More...
 
void serialize (const Mat &, SerializedPosition *)
 Serialize 3D mappoint position, a 3x1 float Mat. More...
 
void serialize (const KeyPoint &, SerializedKeypoint *)
 Serialize 4 properties of a KeyPoint. More...
 
void serialize (const OsmapMapPoint &, SerializedMappoint *)
 Serializes a MapPoint, according to options. More...
 
int serialize (const vector< OsmapMapPoint *> &, SerializedMappointArray &)
 Serialized array of MapPoints. More...
 
void serialize (const OsmapKeyFrame &, SerializedKeyframe *)
 Serialize a KeyFrame. More...
 
int serialize (const vector< OsmapKeyFrame *> &, SerializedKeyframeArray &)
 Serialized array of KeyFrames. More...
 
void serialize (const OsmapKeyFrame &, SerializedKeyframeFeatures *)
 Serialize all features observed by a KeyFrame. More...
 
int serialize (const vector< OsmapKeyFrame *> &vKF, SerializedKeyframeFeaturesArray &serializedKeyframeFeaturesArray)
 Serialize all keyframe's features from provided keyframes container, to the specified serialization object. More...
 
void setKeyFramesToMap ()
 Populate Map.mspKeyFrames with MapPoints from vectorKeyFrames. More...
 
void setMapPointsToMap ()
 Populate Map.mspMapPoints with MapPoints from vectorMapPoints. More...
 
bool writeDelimitedTo (const google::protobuf::MessageLite &message, google::protobuf::io::ZeroCopyOutputStream *rawOutput)
 Writes a message to a vector file. More...
 

Public Attributes

Frame & currentFrame
 Any frame, to copy configuration values from. More...
 
KeyFrameDatabase & keyFrameDatabase
 Database of keyframes to be build after loading. More...
 
vector< unsigned int > keyframeid2vectorkIdx
 For each index KeyFrame.mnId the value returned is an index to vectorK. More...
 
OsmapMapmap
 ORB-SLAM2 map to be serialized. More...
 
bitset< 32 > options = 0
 Set of chosen options for serializing. More...
 
KeyFrame * pRefKF = NULL
 This keyframe is a vehicle to MapPoint construction, which need a pRefKF as argument. More...
 
System & system
 System, needed to populate new keyframes after construction on deserialization, with some configuration values. More...
 
vector< Mat const * > vectorK
 Usually there is only one common matrix K for all KeyFrames in the entire map, there can be more, but there won't be as many K as KeyFrames. More...
 
vector< OsmapKeyFrame * > vectorKeyFrames
 Buffer where map's keyframes are stored in ascending id order, to save them to file in this order. More...
 
vector< OsmapMapPoint * > vectorMapPoints
 Buffer where map's mappoints are stored in ascending id order, to save them to file in this order. More...
 
bool verbose = false
 Whether or not print on console info for debuging. More...
 

Detailed Description

This is a class for a singleton attached to ORB-SLAM2's map.

Its constructor attaches it to the map. Its methods mapLoad and mapSave load and save a map.

A map is saved to a set of files in the actual folder, with a filename provided:

  • filename.keyframes
  • filename.mappoints
  • filename.features
  • filename.yaml, the header

The header is the only text file, in yaml format. Other files are in binary format. keyframes, mappoints and features files consist on a single protocol buffers 3 message. features file can also be an ad hoc delimited array of protocol buffers 3 messages.

Protocol buffers messages format can be found in osmap.proto file. Some of these objects has another object like KeyPoint, nested serialized with the appropiate serialize signature.

Methods:

  • serialize(object, message): this method provides many signatures for many pairs {object, message},const where object, passed by reference, is the instance to be serialized (Mat, MapPoint, KeyFrame, etc.) and message is the protocol buffers destination object.
  • deserialize(message, object): this method provides many signatures for many pairs {object, message}, where message is the protocol buffers source object, and object (Mat, MapPoint, KeyFrame, etc.) is the actual destination. For MapPoint and KeyFrame, object can be either passed by reference or not provided at all, the method creates an empty one, and returns it deserialized.
  • messageArray is a message with only one field of repeated messages. messageArray serialized MapPoints, KeyFrames, Features...

General rules:

  • deserialize get a const message
  • serialize need a mutable message, it asks for a pointer to mutable message, as provided by protocol buferrs' mutable_field and add_field
  • serializeArray and deserializeArray serialize a messageArray, i.e. set of objects
  • unlike serialize, serializeArray uses a messageArray, not a pointer to it.

Usage example:

In Orb-Slam2's main.cc, this code will save and load a map:

...

Construct the osmap object, can be right after SLAM construction. You only need one instance to load and save as many maps you want. Osmap osmap = ORB_SLAM2::Osmap(SLAM); ... Whe you already has a map to save osmap.mapSave("myFirstMap"); // "myFirstMap" or "myFirstMap.yaml", same thing ... Now you want to load the map osmap.mapLoad("myFirstMap.yaml");

In Linux, zenity comes handy as dialog to get file name to load and save map. You need zenity installed, this runs the command line:

char cstringfilename[1024];

Load dialog FILE *f = popen("zenity --file-selection", "r"); fgets(cstringfilename, 1024, f);

Save dialog FILE *f = popen("zenity --file-selection --save --confirm-overwrite --filename=mapa", "r"); fgets(cstringfilename, 1024, f);

You probably want to go to localization only mode (tracking only, no mapping) right before saving or loading. To do that:

SLAM->ActivateLocalizationMode();

User also can control this with the button "Localization mode" in viewer.

Member Enumeration Documentation

All the options available.

Options are persetted into options property. Default is zero. Options are activated with 1.

To test an option:

if(options[ORB_SLAM2::Osmap::ONLY_MAPPOINTS_FEATURES])...

To set an option:

options.set(ORB_SLAM2::Osmap::ONLY_MAPPOINTS_FEATURES);

Available options are documented in enum Options. New options can be added in the future, but the order of existing options must be keeped. So, new options must be added to the end of enum.

Time stamp is not optional because it always occupy place in protocol buffers, as all numeric fields. Defaults to 0.

Options are saved in the map file. NO_SET_BAD is the only option one can have insterest to set before loading, while not set in the file.

Enumerator
FEATURES_FILE_DELIMITED 

Saves features file in delimited form: many protocol buffers messages in one file.

FEATURES_FILE_NOT_DELIMITED 

Avoids saving features file in delimited form: only one protocol buffers message in the file, as always done with mappoints and keyframes.

NO_MAPPOINTS_FILE 

Skip saving mappoints file. Map will be incomplete, only for analysis porpouses.

NO_KEYFRAMES_FILE 

Skip saving keyframes file. Map will be incomplete, only for analysis porpouses.

NO_FEATURES_FILE 

Skip saving features file. Map will be incomplete, only for analysis porpouses.

NO_FEATURES_DESCRIPTORS 

Skip saving descriptors in features file. Descriptors are saved only in mappoints. It is usually used with ONLY_MAPPOINTS_FEATURES to notable reduce features file size.

ONLY_MAPPOINTS_FEATURES 

Skip saving features that not belong to mappoints. This notable reduce features file size. Map will be fine for tracking, may get a little hard (not impossible) to continue mapping.

NO_LOOPS 

Skip saving and retrieving (loading) loops edges. Not expected size reduction. Map will work. For debug and analysis porpouses.

K_IN_KEYFRAME 

Force saving K camera matrix on each keyframe instead of saving them on yaml file. Keyframes file will increase.

NO_DEPURATION 

Avoids map depuration process before save. Depuration get rid of bad elements, but could ruin the map if illformed.

NO_SET_BAD 

Avoids bad mappoints and keyframe detection while rebuilding the map, right after load. Used with dummy maps examples to prevent anomally detection, because dummy maps have incomplete class implementations.

NO_APPEND_FOUND_MAPPOINTS 

On depuration process before save, avoids adding to the map any found good mappoint erroneously deleted from map.

OPTIONS_SIZE 

< Number of options. Not an option.

Constructor & Destructor Documentation

ORB_SLAM2::Osmap::Osmap ( System &  _system)

Only constructor, the only way to set the orb-slam2 map.

Member Function Documentation

void ORB_SLAM2::Osmap::clearVectors ( )

Clear temporary vectors.

Only clears the vectors, not the objects its pointer elements pointed to (keyframes, mappoints, K matrices), because they belong to the map.

int ORB_SLAM2::Osmap::countFeatures ( )

Count the number of features in vectorKeyFrames.

Invoked by mapSave to decide to use or not delimited form of feature file.

void ORB_SLAM2::Osmap::depurate ( )

Irons keyframes and mappoints sets in map, before save.

Tests all keyframes in MapPoints.mObservations and mappoints in KeyFrames.mvpMapPoints, checking they are:

  • not bad (!isBad())
  • in map (in Map::mspMapPoints and Map::mspKeyFrames)

Those who not pass this check are eliminated, avoiding serialization of elements not belonging to the map.

This depuration affects (improves) the actual map in memory.

Invoked by mapSave.

void ORB_SLAM2::Osmap::deserialize ( const SerializedK &  ,
Mat &  k 
)

Reconstruct the intrinsic camera matrix K from protocol buffer message.

All 4 fields are required.

Parameters
serializedKProtocol buffers source message.
kDestination to be reconstruted. K matrix, also known as calibration matrix, instrinsic matrix and camera matrix, 3x3 float Mat, usually from KeyFrame::mK.
void ORB_SLAM2::Osmap::deserialize ( const SerializedKArray &  serializedKArray,
vector< Mat *> &  vK 
)

Reconstruct an array of camera calibration matrix K.

The array should be retrieved from keyframes analisys. Usually there is only one K common to all keyframes.

Parameters
serializedKArrayThe serialization destination object.
vKThe vector of K matrices to serialize. Usually Osmap::vectorK member.
void ORB_SLAM2::Osmap::deserialize ( const SerializedDescriptor &  ,
Mat &   
)

Reconstruct a descriptor, an 1x32 uchar Mat (256 bits).

Exactly 8 int required.

void ORB_SLAM2::Osmap::deserialize ( const SerializedPose &  ,
Mat &   
)

Reconstruct a 4x4 float Mat representing a pose in homogeneous coordinates.

Exactly 12 float required.

void ORB_SLAM2::Osmap::deserialize ( const SerializedPosition &  ,
Mat &   
)

Reconstructs 3D mappoint position in a 3x1 float Mat.

All 3 fields required.

void ORB_SLAM2::Osmap::deserialize ( const SerializedKeypoint &  ,
KeyPoint &   
)

Reconstructs a KeyPoint.

All 4 fields required.

OsmapMapPoint* ORB_SLAM2::Osmap::deserialize ( const SerializedMappoint &  serializedMappoint)

Creates and fills a MapPoint from optional message fields.

It doesn't perform MapPoint initialization. This should be done after deserialization.

Parameters
serializedMappointProtocol buffers source message.
Returns
*MapPoint A pointer to the newly created MapPoint, ready to be added to the map.
int ORB_SLAM2::Osmap::deserialize ( const SerializedMappointArray &  ,
vector< OsmapMapPoint *> &   
)

Retrieves MapPoints from an array, and append them to the map.

Parameters
serializedMapPointArraymessage to set up. Data goes to the output iterator.
outputiterator on the destination container. Usually std::inserter(mspMapPoints, mspMapPoints.end()). For vector it can be a Back inserter iterator where output is placed in arrival order. Usually mspMapPoints.begin(). About set back_inserter: https://stackoverflow.com/questions/908272/stdback-inserter-for-a-stdset
Returns
Number of MapPoints retrieved or -1 if error. Map's MapPoints set should be emptied before calling this method.
OsmapKeyFrame* ORB_SLAM2::Osmap::deserialize ( const SerializedKeyframe &  )

Reconstructs a KeyFrame from optional fields.

It doesn't perform KeyFrame initialization. This should be done after deserialization.

int ORB_SLAM2::Osmap::deserialize ( const SerializedKeyframeArray &  ,
vector< OsmapKeyFrame *> &   
)

Retrieves MapPoints from an array, and append them to the map.

Parameters
serializedMapPointArraymessage to set up. Data goes from map.
Returns
Number of MapPoints retrieved or -1 if error. Map's MapPoints set should be emptied before calling this method.
OsmapKeyFrame* ORB_SLAM2::Osmap::deserialize ( const SerializedKeyframeFeatures &  )

Retrieves all features belonging to one keyframe.

First it takes the required keyframe_id field, and look in map for the keyframe with that id. Hence, keyframes must be already deserialized in map.

Puts all KeyPoints, MapPoints* and descriptors in their respective containters of the provided KeyFrame.

Parameters
SerializedKeyframeFeaturesObject to be deserialized.
int ORB_SLAM2::Osmap::deserialize ( const SerializedKeyframeFeaturesArray &  )

Retrieves all keyframe's features from the specified serialization object to vectorKeyframe.

int ORB_SLAM2::Osmap::featuresLoad ( string  filename)

Load the content of a "map.features" file and applies it to vectorKeyFrames.

Parameters
filenamefull name of the file to open.
int ORB_SLAM2::Osmap::featuresSave ( string  filename)

Save KeyFrane's features of vectorKeyFrames to file, usually "map.features".

Parameters
filenamefull name of the file to be created and saved.
OsmapKeyFrame* ORB_SLAM2::Osmap::getKeyFrame ( unsigned int  id)

Looks for a KeyFrame id in the map.

Keyframes are usually stored in ascending id order. This function will be more probably called in the same way, so it is optimized for this expected behaviour. It uses itLastKF.

Parameters
idId of the KeyFrame to look for.
Returns
a pointer to the KeyFrame with the given id, or NULL if not found. Used only in Osmap::deserialize(const SerializedKeyframeFeatures&).
void ORB_SLAM2::Osmap::getKeyFramesFromMap ( )

Populate vectorKeyFrames with MapPoints from Map.mspKeyFrames.

This is done as the first step to save keyframes.

MapPoint* ORB_SLAM2::Osmap::getMapPoint ( unsigned int  id)

Looks for a mappoint by its id in the map.

Parameters
idId of the MapPoint to look for.
Returns
a pointer to the MapPoint with the given id, or NULL if not found.
void ORB_SLAM2::Osmap::getMapPointsFromMap ( )

Populate vectorMapPoints with MapPoints from Map.mspMapPoints.

This is done as the first step to save mappoints.

void ORB_SLAM2::Osmap::getVectorKFromKeyframes ( )

Traverse map's keyframes looking for different K matrices, and stores them into vectorK.

It also populates keyframeid2vectork.

int ORB_SLAM2::Osmap::KeyFramesLoad ( string  filename)

Load the content of a "map.keyframes" file to vectorKeyFrames.

Parameters
filenamefull name of the file to open.
int ORB_SLAM2::Osmap::KeyFramesSave ( string  filename)

Save the content of vectorKeyFrames to file like "map.keyframes".

Need

Parameters
filenamefull name of the file to be created and saved.
Returns
number of keyframes serialized. -1 if error.

This method ignores option NO_KEYFRAMES_FILE

void ORB_SLAM2::Osmap::log ( )
inline
template<typename Head , typename... Args>
void ORB_SLAM2::Osmap::log ( const Head &  head,
const Args &...  args 
)
inline
void ORB_SLAM2::Osmap::mapLoad ( string  yamlFilename,
bool  noSetBad = false,
bool  pauseThreads = true 
)

Loads the map from a set of files in the folder whose name is provided as an argument.

This is the entry point to load a map. This method uses the Osmap object to serialize the map to files.

Parameters
yamlFilenamefile name of .yaml file (including .yaml extension) describing a map.
noSetBadtrue to avoid bad mappoints and keyframes deletion on rebuilding after loading.
stopTrheadsSerializing needs some orb-slam2 threads to be paused. true (the default value) signals mapLoad to pause the threads before saving, and resume them after saving. false when threads are paused and resumed by other means.

Only these properties are read from yaml:

  • file nKeyframes
  • options
  • camera calibration matrices K
  • other files' names

Before calling this method, threads must be paused.

int ORB_SLAM2::Osmap::MapPointsLoad ( string  filename)

Load the content of a "map.mappoints" file to vectorMapPoints.

Parameters
filenamefull name of the file to open.
int ORB_SLAM2::Osmap::MapPointsSave ( string  filename)

Save the content of vectorMapPoints to file like "map.mappoints".

Parameters
filenamefull name of the file to be created and saved.
Returns
number of mappoints serialized. -1 if error.

This method ignores option NO_MAPPOINTS_FILE If not K_IN_KEYFRAME option (the default), vectorK must be populated (see getVectorKFromKeyframes) prior invocation of this method.

void ORB_SLAM2::Osmap::mapSave ( string  basefilename,
bool  pauseThreads = true 
)

Saves the map to a set of files in the actual directory, with the extensionless name provided as the only argument and different extensions for each file.

If filename has .yaml extension, mapSave will remove it to get the actual basefilename. Any existing file is rewritten without warning. This is the entry point to save a map. This method uses the Osmap object to serialize the map to files. Before calling this method:

  • ORB-SLAM2 threads must be stopped to assure map is not being modify while saving.
  • Actual directory must be set to the desired destination. Often a new directory exclusive for the map is created.
  • options must be set.
Parameters
basefilenameFile name without extenion or with .yaml extension. Many files will be created with this basefilename and different extensions.
pauseThreadsSerializing needs some orb-slam2 threads to be paused. true (the default value) signals mapSave to pause the threads before saving, and resume them after saving. false when threads are paused and resumed by other means.

MapSave copy map's mappoints and keyframes sets to vectorMapPoints and vectorKeyFrames and sort them, to save objects in ascending id order. MapLoad doesn't use those vector.

If features number exceed an arbitrary maximum, in order to avoid size related protocol buffer problems, mapSave limit the size of protocol buffer's messages saving features file in delimited form, using Kendon Varda writeDelimitedTo function.

void ORB_SLAM2::Osmap::parsePath ( const string &  path,
string *  filename = NULL,
string *  pathDirectory = NULL 
)

Utility for separating path and filename from a full path.

Parameters
filenameOutput string, filename found in path, '' if no file in the path. Can be NULL.
pathDirectoryOutput string with the directory's path, '' if none. Can be NULL.
bool ORB_SLAM2::Osmap::readDelimitedFrom ( google::protobuf::io::ZeroCopyInputStream *  rawInput,
google::protobuf::MessageLite *  message 
)

Reads a message to a vector file.

A vector file is an array of messages.

Parameters
message
rawOutputinput stream, readable source file.
Returns
true if ok, false if error.

Kendon Varda code to serialize many messages in one file, from https://stackoverflow.com/questions/2340730/are-there-c-equivalents-for-the-protocol-buffers-delimited-i-o-functions-in-ja

void ORB_SLAM2::Osmap::rebuild ( bool  noSetBad = false)

Rebuilding takes place right after loading a map from files, before the map is copied to ORB-SLAM2' sets.

Works on Osmap::vectorMapPoints and Osmap::vectorKeyFrames. After rebuilding, the elements in these vector should be copied to the map sets.

rebuild() needs KeyPoints and MapPoints to be initialized with a lot of properties set, as the default constructors for OsmapKeyFrame and OsmapMapPoint show.

Parameters
noSetBadtrue to avoid bad mappoints and keyframes deletion on rebuilding.

This method checks Osmap::verbose property to produce console output for debugging purposes.

How rebuild works:

  • Loops on every keyframe:
    • ComputeBOW, building BOW vectors from descriptors
    • Builds many pose matrices from pose
    • Builds the grid
    • Adds to KeyFrameDatabase
    • Builds its mappoints observations
    • UpdateConnections, building the spaning tree and the covisibility graph
  • Sets KeyFrame::nNextId
  • Retries UpdateConnections on isolated keyframes.
  • Sets bad keyframes remaining isolated (avoided with noSetBad argument true)
  • Sets map.mvpKeyFrameOrigins
  • Travels keyframes looking for orphans, trying to assign a parent, thus including them in the spanning tree.
  • Loops on every mappoint:
    • Sets bad mappoints without observations (avoided with noSetBad argument true)
    • Sets mpRefKF
    • UpdateNormalAndDepth, setting mNormalVector, mfMinDistance, mfMaxDistance
  • Sets MapPoint::nNextId
void ORB_SLAM2::Osmap::serialize ( const Mat &  k,
SerializedK *  serializedK 
)

Serialize provided intrinsic camera matrix K to the protocol buffer message.

All 4 fields required.

Parameters
kSource to be serialized. K matrix, also known as calibration matrix, instrinsic matrix and camera matrix, 3x3 float Mat, usually from KeyFrame::mK.
serializedKProtocol buffers destination message to be serialized.
void ORB_SLAM2::Osmap::serialize ( const vector< Mat *> &  vK,
SerializedKArray &  serializedKArray 
)

Serialize an array of camera calibration matrix K.

The array should be retrieved from keyframes analisys. Usually there is only one K common to all keyframes.

Parameters
vKThe vector of K matrices to serialize.
serializedKArrayThe serialization destination object.
void ORB_SLAM2::Osmap::serialize ( const Mat &  ,
SerializedDescriptor *   
)

Serializes a descriptor, an 1x32 uchar Mat (256 bits).

Protocol Buffers doesn't have a Byte type, so it's serialized to 8 int. Exactly 8 int required.

void ORB_SLAM2::Osmap::serialize ( const Mat &  ,
SerializedPose *   
)

Serialize a 4x4 float Mat representing a pose in homogeneous coordinates.

Exactly 12 float required.

void ORB_SLAM2::Osmap::serialize ( const Mat &  ,
SerializedPosition *   
)

Serialize 3D mappoint position, a 3x1 float Mat.

All 3 fields required.

void ORB_SLAM2::Osmap::serialize ( const KeyPoint &  ,
SerializedKeypoint *   
)

Serialize 4 properties of a KeyPoint.

All 4 fields required.

void ORB_SLAM2::Osmap::serialize ( const OsmapMapPoint ,
SerializedMappoint *   
)

Serializes a MapPoint, according to options.

int ORB_SLAM2::Osmap::serialize ( const vector< OsmapMapPoint *> &  ,
SerializedMappointArray &   
)

Serialized array of MapPoints.

The serialized message can be saved to an exclusive file, or be appended to a multiobject file.

Parameters
startInclusive begining of the range of MapPoints to be serialized. Usually map.mspMapPoints.begin().
endExclusive end of the range of MapPoints to be serialized. Usually map.mspMapPoints.end().
serializedMapPointArraymessage to set up. Data comes from the range iterated.
Returns
Number of MapPoints serialized or -1 if error. The number of MapPoints serialized should be the same number of MapPoints in the map.
void ORB_SLAM2::Osmap::serialize ( const OsmapKeyFrame ,
SerializedKeyframe *   
)

Serialize a KeyFrame.

Serialization and deserialization assume KeyFrames are processed in ascending id order.

int ORB_SLAM2::Osmap::serialize ( const vector< OsmapKeyFrame *> &  ,
SerializedKeyframeArray &   
)

Serialized array of KeyFrames.

This can make a file, or be appended to a multiobject file. KeyFrames will be serialized in ascending id order.

Parameters
serializedKeyFrameArraymessage to set up. Data comes from map.
Returns
Number of KeyFrames serialized or -1 if error. The number of KeyFrames serialized should be the same number of MapPoints in the map.
void ORB_SLAM2::Osmap::serialize ( const OsmapKeyFrame ,
SerializedKeyframeFeatures *   
)

Serialize all features observed by a KeyFrame.

Parameters
pKFKeyFrame owner of the feature. The features will be stored in this KeyFrame containers.
SerializedKeyframeFeaturesMessage destination of serialization.
Returns
The serialized message object.
int ORB_SLAM2::Osmap::serialize ( const vector< OsmapKeyFrame *> &  vKF,
SerializedKeyframeFeaturesArray &  serializedKeyframeFeaturesArray 
)

Serialize all keyframe's features from provided keyframes container, to the specified serialization object.

Parameters
vKFvector of KeyFrames to save, usually vectorKeyFrames member order by mnId.
serializedKeyframeFeaturesArrayoutput serialization object.
void ORB_SLAM2::Osmap::setKeyFramesToMap ( )

Populate Map.mspKeyFrames with MapPoints from vectorKeyFrames.

This is done after loading keyframes.

void ORB_SLAM2::Osmap::setMapPointsToMap ( )

Populate Map.mspMapPoints with MapPoints from vectorMapPoints.

This is done after loading mappoints.

bool ORB_SLAM2::Osmap::writeDelimitedTo ( const google::protobuf::MessageLite &  message,
google::protobuf::io::ZeroCopyOutputStream *  rawOutput 
)

Writes a message to a vector file.

A vector file is an array of messages. In order to possibilitate deserialization, the message size is prepended to the message.

Parameters
message
rawOutputoutput stream, writable destination file.
Returns
true if ok, false if error.

Kendon Varda code to serialize many messages in one file, from https://stackoverflow.com/questions/2340730/are-there-c-equivalents-for-the-protocol-buffers-delimited-i-o-functions-in-ja

When writing to a file, *rawOutput object must be deleted before closing the file, to ensure flushing.

Member Data Documentation

Frame& ORB_SLAM2::Osmap::currentFrame

Any frame, to copy configuration values from.

Constructor takes currentFrame from Tracker.

KeyFrameDatabase& ORB_SLAM2::Osmap::keyFrameDatabase

Database of keyframes to be build after loading.

vector<unsigned int> ORB_SLAM2::Osmap::keyframeid2vectorkIdx

For each index KeyFrame.mnId the value returned is an index to vectorK.

The later is the index saved in each keyframe as k. It is populated only by getVectorKFromKeyframes, and consumed only while saving the map, during keyframe serialization.

OsmapMap& ORB_SLAM2::Osmap::map

ORB-SLAM2 map to be serialized.

bitset<32> ORB_SLAM2::Osmap::options = 0

Set of chosen options for serializing.

User must set options prior to saving a map. Loading a map should reflect in this property the saved map options.

KeyFrame* ORB_SLAM2::Osmap::pRefKF = NULL

This keyframe is a vehicle to MapPoint construction, which need a pRefKF as argument.

MapPoint construction occurs only while loading. pRefKF can be any KeyFrame. mapLoad can be invoked when there is no map in orbslam2, which means there is no keyframe in it. So Osmap constructs one. But constructed a KeyFrame requires a populated Frame (Osmap uses tracker.currentFrame), and it isn't populated with data before first tracking loop. This means pRefKF can't be constructed in Osmap constructor. pRefKF keyframe is constructed on the first map load, more specifically right before mappoints are loaded.

System& ORB_SLAM2::Osmap::system

System, needed to populate new keyframes after construction on deserialization, with some configuration values.

vector<Mat const *> ORB_SLAM2::Osmap::vectorK

Usually there is only one common matrix K for all KeyFrames in the entire map, there can be more, but there won't be as many K as KeyFrames.

This vector temporarily store different K for serialization and deserialization. This avoids serializing one K per KeyFrame. This vector is consumed in keyframe deserialization.

vector<OsmapKeyFrame*> ORB_SLAM2::Osmap::vectorKeyFrames

Buffer where map's keyframes are stored in ascending id order, to save them to file in this order.

This vector is set in mapSave, and it's left ontouched for user interest.

vector<OsmapMapPoint*> ORB_SLAM2::Osmap::vectorMapPoints

Buffer where map's mappoints are stored in ascending id order, to save them to file in this order.

This vector is set in mapSave, and it's left ontouched for user interest. This vector is consumed in serialize

bool ORB_SLAM2::Osmap::verbose = false

Whether or not print on console info for debuging.


The documentation for this class was generated from the following file: