Class FileStorage

Class Documentation

class FileStorage

Class to store lib3D image and camera data into files.

Files can be stored in a binary or an ascii format, the latter being useful for debug purposes.

Storing of image data

Binary format

When the binary format the image data is stored into mixed text and binary files. The text header holds the version of the lib3D_core module, the type id of the data as well as the dimensions of the image in the format ‘CoreVersion&TypeId&Width&Height&Channels&’. After the header the data is stored as row-major format. The TypeId field will hold the value returned by ‘typeid(T).name’, i.e. ‘d’ for double.

The file ending is constructed with a prefix and the content string of the image, i.e. (.lib3d<contentStr>). For example, ‘lib3ddepth’ for depth maps. The type id of the data is not encoded into the file name, thus when storing ‘DepthMap’ and ‘DDepthMap’ the file endings will be the same. A check for the use of correct type id is done when parsing the file.

ASCII format

When the ascii format the image data is stored into a XML formatted ascii file which can be opened in a text editor. In this the ‘cv::FileStorage’ is utilized. It will save the verison string of the lib3D_core module as well as the data of the image.

The file ending is constructed with a prefix and the content string of the image followed by ‘.xml’ to indicate the intention for debug purposes, i.e. (.lib3d<contentStr>.xml).

Storing of camera data

Binary format

Similiar to saving iamge data to files, the camera data is stored into mixed text and binary files ending with ‘.lib3dcamera’. At the beginning of the file stands the version string of lib3D_core followed by the header for the intrinsic camera data, ‘CoreVersion&K&TypeId&NumOfParameters&’. The data that follows are the parameters of the calibration matrix \(K\) of type stated in TypeId. After the parameter data of the calibration matrix comes the header for the distortion parameters, ‘&D&TypeId&NumOfParameters&’ followe by the actual data. Afterwards comes the header for the extrinsic matrix of the camera, ‘&RT&TypeId&NumOfParameters&’, together with the actual data.

ASCII format

Again, when using an ascii format, the ‘cv::FileStorage’ is utilized. It will save the verison string of the lib3D_core module as well as the data of the camera into ascii files ending with ‘.lib3dcamera.xml’

Example

In this short example an object of a camera model, a depth map and a normal map is initialized and written to binary files in a specified output directory.

...

// create camera object, depth map and normal map
lib3d::Camera camera;
lib3d::DepthMap depthMap;
lib3d::NormalMap normalMap;

// ... Fill with data

// specify file name without extension
std::string fileName = "foo";

// sepcify output directory
std::string outputDir = "/home/user/foo_output/";

// write to binary files in outputDir
lib3d::FileStorage lib3dFS(outputDir, lib3d::FileStorage::BIN);
lib3dFS.writeCameraModel(fileName, camera);
lib3dFS.writeDepthMap(fileName, depthMap);
lib3dFS.writeNormalMap(fileName, normalMap);

...

Public Types

enum EFileFormat

Enumeration holding possible formats in which the files can be stored.

Values:

enumerator BIN
enumerator ASCII

Public Functions

inline explicit FileStorage()

Default constructor initializing the base directory with ‘./’ and a binary file format.

inline explicit FileStorage(const std::string &iBaseDirPath, const EFileFormat &iFileFormat = BIN)

Initialization constructor.

Parameters:
  • iBaseDirPath[in] Path to base directory in which the data is to be stored.

  • iFileFormat[in] File format to use.

inline explicit FileStorage(const QDir &iBaseDir, const EFileFormat &iFileFormat = BIN)

Initialization constructor.

Parameters:
  • iBaseDir[in] Base directory in which the data is to be stored.

  • iFileFormat[in] File format to use.

inline virtual ~FileStorage()
inline QDir baseDir() const

Returns base directory in which the data is to be stored.

inline void setBaseDir(const QDir &baseDir)

Set base directory in which the data is to be stored.

inline void setBaseDir(const std::string &iDirPath)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

iDirPath[in] Path to diretory.

inline EFileFormat fileformat() const

Returns file format to use.

inline void setFileformat(const EFileFormat &fileformat)

Set file format to use.

inline bool writeCameraModel(const std::string &iFilename, const Camera &iCamObj)

Write camera model to file.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Can be given with or without file ending. If the corresponding file ending (.lib3dcamera) is not provided, it will be appended to the file. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • iCamObj[in] Camera object that is to be stored.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

inline bool writeCameraModel(const std::string &iFilename, const Camera &iCamObj, const QDir &iSubdir)

Write camera model to file.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Can be given with or without file ending. If the corresponding file ending (.lib3dcamera) is not provided, it will be appended to the file. The file name is to be given relative to the base directory (setBaseDir()) and the subdirectory (iSubDir).

  • iCamObj[in] Camera object that is to be stored.

  • iSubdir[in] Subdirectory in which the file is to be stored. If subdirectory does not exists it is created before the file is stored.

Returns:

False, if not successful. True, otherwise.

inline bool readCameraModel(const std::string &iFilename, Camera &oCamObj)

Read camera model from file.

Note

The method will check if the type of data stored inside the file corresponds to the camera object.

Parameters:
  • iFilename[in] Name of the file in which the data is to be stored. Is to be given with file ending (.lib3dcamera). The file name is to be given relative to the base directory (setBaseDir()).

  • oCamObj[out] Camera object in which the data is to be read.

Returns:

False, if not successful (e.g. data types are incompatible). True, otherwise.

inline bool readCameraModel(const std::string &iFilename, Camera &oCamObj, const QDir &iSubdir)

Read camera model from file.

Note

The method will check if the type of data stored inside the file corresponds to the camera object.

Parameters:
  • iFilename[in] Name of the file in which the data is to be stored. Is to be given with file ending (.lib3dcamera). The file name is to be given relative to the base directory (setBaseDir()) and the subdirectory (iSubDir).

  • oCamObj[out] Camera object in which the data is to be read.

  • iSubdir[in] Subdirectory in which the file is stored. If subdirectory does not exists the method will return false.

Returns:

False, if not successful (e.g. data types are incompatible). True, otherwise.

template<typename T, int l>
inline bool writeImageData(const std::string &iFilename, const Image<T, l> &iImgObj)

Template method to write image data to file.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Can be given with or without file ending. If the corresponding file ending (.lib3d<contentStr>) is not provided, it will be appended to the file. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • iImgObj[in] Image object that is to be stored.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

inline bool writeColorImage(const std::string &iFilename, const ColorImage &iImgObj)

Write color image to file.

See also

writeImageData() for more information

inline bool writeGraysaleImage(const std::string &iFilename, const GrayscaleImage &iImgObj)

Write grayscale image to file.

See also

writeImageData() for more information

inline bool writeDepthMap(const std::string &iFilename, const DepthMap &iImgObj)

Write depth map to file.

See also

writeImageData() for more information

inline bool writeDepthMap(const std::string &iFilename, const DepthMapD &iImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeDisparityMap(const std::string &iFilename, const DisparityMap &iImgObj)

Write disparity map to file.

See also

writeImageData() for more information

inline bool writeDisparityMap(const std::string &iFilename, const DisparityMapD &iImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeConfidenceMap(const std::string &iFilename, const ConfidenceMap &iImgObj)

Write confidence map to file.

See also

writeImageData() for more information

inline bool writeConfidenceMap(const std::string &iFilename, const ConfidenceMapD &iImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeNormalMap(const std::string &iFilename, const NormalMap &iImgObj)

Write normal map to file.

See also

writeImageData() for more information

inline bool writeNormalMap(const std::string &iFilename, const NormalMapD &iImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeVisImage(const std::string &iFilename, const cv::Mat &iImgObj)

Write image to visual file (e.g. png, jpg, …) using write routine from OpenCV.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Needs to be given with desired file ending (e.g. png, jpg, …) in order for OpenCV to know, which encoding to use. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • iImgObj[in] Image object that is to be stored.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool writeImageData(const std::string &iFilename, const Image<T, l> &iImgObj, const QDir &iSubdir)

Template method to write iamge model to file.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Can be given with or without file ending. If the corresponding file ending (.lib3d<contentStr>) is not provided, it will be appended to the file. The file name is to be given relative to the base directory (setBaseDir()) and the subdirectory (iSubDir).

  • iImgObj[in] Image object that is to be stored.

  • iSubdir[in] Subdirectory in which the file is to be stored. If subdirectory does not exists it is created before the file is stored.

Returns:

False, if not successful. True, otherwise.

inline bool writeColorImage(const std::string &iFilename, const ColorImage &iImgObj, const QDir &iSubdir)

Write color image to file.

See also

writeImageData() for more information

inline bool writeGraysaleImage(const std::string &iFilename, const GrayscaleImage &iImgObj, const QDir &iSubdir)

Write grayscale image to file.

See also

writeImageData() for more information

inline bool writeDisparityMap(const std::string &iFilename, const DisparityMap &iImgObj, const QDir &iSubdir)

Write disparity map to file.

See also

writeImageData() for more information

inline bool writeDisparityMap(const std::string &iFilename, const DisparityMapD &iImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeDepthMap(const std::string &iFilename, const DepthMap &iImgObj, const QDir &iSubdir)

Write depth map to file.

See also

writeImageData() for more information

inline bool writeDepthMap(const std::string &iFilename, const DepthMapD &iImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeConfidenceMap(const std::string &iFilename, const ConfidenceMap &iImgObj, const QDir &iSubdir)

Write confidence map to file.

See also

writeImageData() for more information

inline bool writeConfidenceMap(const std::string &iFilename, const ConfidenceMapD &iImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeNormalMap(const std::string &iFilename, const NormalMap &iImgObj, const QDir &iSubdir)

Write normal map to file.

See also

writeImageData() for more information

inline bool writeNormalMap(const std::string &iFilename, const NormalMapD &iImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool writeVisImage(const std::string &iFilename, const cv::Mat &iImgObj, const QDir &iSubdir)

Write image to visual file (e.g. png, jpg, …) using write routine from OpenCV.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Needs to be given with desired file ending (e.g. png, jpg, …) in order for OpenCV to know, which encoding to use. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • iImgObj[in] Image object that is to be stored.

  • iSubdir[in] Subdirectory in which the file is to be stored. If subdirectory does not exists it is created before the file is stored.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool readImageData(const std::string &iFilename, Image<T, l> &oImgObj)

Template method to read image data from file.

Note

The method will check if the type of data stored inside the file corresponds to the image object.

Parameters:
  • iFilename[in] Name of the file in which the data is to be stored. Is to be given with file ending (.lib3d<contentStr>). The file name is to be given relative to the base directory (setBaseDir()).

  • oImgObj[out] Image object in which the data is to be read.

Returns:

False, if not successful (e.g. data types are incompatible). True, otherwise.

inline bool readColorImage(const std::string &iFilename, ColorImage &oImgObj)

Read color image from file.

See also

readImageData() for more information

inline bool readGraysaleImage(const std::string &iFilename, GrayscaleImage &oImgObj)

Read grayscale image from file.

See also

readImageData() for more information

inline bool readDepthMap(const std::string &iFilename, DepthMap &oImgObj)

Read depth map from file.

See also

readImageData() for more information

inline bool readDepthMap(const std::string &iFilename, DepthMapD &oImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readDisparityMap(const std::string &iFilename, DisparityMap &oImgObj)

Read disparity map from file.

See also

readImageData() for more information

inline bool readDisparityMap(const std::string &iFilename, DisparityMapD &oImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readConfidenceMap(const std::string &iFilename, ConfidenceMap &oImgObj)

Read confidence map from file.

See also

readImageData() for more information

inline bool readConfidenceMap(const std::string &iFilename, ConfidenceMapD &oImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readNormalMap(const std::string &iFilename, NormalMap &oImgObj)

Read normal map from file.

See also

readImageData() for more information

inline bool readNormalMap(const std::string &iFilename, NormalMapD &oImgObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readVisImage(const std::string &iFilename, cv::Mat &oImgObj)

Read visual image file (e.g. png, jpg, …) using write routine from OpenCV.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Needs to be given with desired file ending (e.g. png, jpg, …) in order for OpenCV to know, which encoding to use. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • oImgObj[out] Output image.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool readImageData(const std::string &iFilename, Image<T, l> &oImgObj, const QDir &iSubdir)

Template method to read image data from file.

Note

The method will check if the type of data stored inside the file corresponds to the camera object.

Parameters:
  • iFilename[in] Name of the file in which the data is to be stored. Is to be given with file ending (.lib3d<contentStr>). The file name is to be given relative to the base directory (setBaseDir()) and the subdirectory (iSubDir).

  • oImgObj[out] Image object in which the data is to be read.

  • iSubdir[in] Subdirectory in which the file is stored. If subdirectory does not exists the method will return false.

Returns:

False, if not successful (e.g. data types are incompatible). True, otherwise.

inline bool readColorImage(const std::string &iFilename, ColorImage &oImgObj, const QDir &iSubdir)

Read color image from file.

See also

readImageData() for more information

inline bool readGraysaleImage(const std::string &iFilename, GrayscaleImage &oImgObj, const QDir &iSubdir)

Read grayscale image from file.

See also

readImageData() for more information

inline bool readDepthMap(const std::string &iFilename, DepthMap &oImgObj, const QDir &iSubdir)

Read depth map from file.

See also

readImageData() for more information

inline bool readDepthMap(const std::string &iFilename, DepthMapD &oImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readDisparityMap(const std::string &iFilename, DisparityMap &oImgObj, const QDir &iSubdir)

Read disparity map from file.

See also

readImageData() for more information

inline bool readDisparityMap(const std::string &iFilename, DisparityMapD &oImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readConfidenceMap(const std::string &iFilename, ConfidenceMap &oImgObj, const QDir &iSubdir)

Read confidence map from file.

See also

readImageData() for more information

inline bool readConfidenceMap(const std::string &iFilename, ConfidenceMapD &oImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readNormalMap(const std::string &iFilename, NormalMap &oImgObj, const QDir &iSubdir)

Read normal map from file.

See also

readImageData() for more information

inline bool readNormalMap(const std::string &iFilename, NormalMapD &oImgObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

inline bool readVisImage(const std::string &iFilename, cv::Mat &oImgObj, const QDir &iSubdir)

Read visual image file (e.g. png, jpg, …) using write routine from OpenCV.

Parameters:
  • iFilename[in] Name of the file into which the data is to be stored. Needs to be given with desired file ending (e.g. png, jpg, …) in order for OpenCV to know, which encoding to use. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • oImgObj[out] Output image.

  • iSubdir[in] Subdirectory in which the file is stored. If subdirectory does not exists the method will return false.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool writeFrame(const std::string &iFilename, const Frame<T, l> &iFrameObj)

Write frame onto disk. This will write the content of the frame into separate files, according to their type.

Parameters:
  • iFilename[in] Name of the files into which the data is to be stored. It is assumed to be given without ending. Thus, the appropriate file endings will be attached. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • iFrameObj[in] Frame object that is to be stored.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool writeFrame(const std::string &iFilename, const Frame<T, l> &iFrameObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

iSubdir[in] Subdirectory in which the file is to be stored. If subdirectory does not exists it is created before the file is stored.

template<typename T, int l>
inline bool writeFrame(const Frame<T, l> &iFrameObj)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will use the name of the frame as file name.

template<typename T, int l>
inline bool writeFrame(const Frame<T, l> &iFrameObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This will use the name of the frame as file name.

template<typename T, int l>
inline bool readFrame(const std::string &iFilename, Frame<T, l> &oFrameObj)

Write frame onto disk. This will write the content of the frame into separate files, according to their type.

Parameters:
  • iFilename[in] Name of the files into which the data is to be stored. It is assumed to be given without ending. Thus, the appropriate file endings will be attached. The file name is to be given relative to the base directory (setBaseDir()). However, if the file lies in a subdirectory it is to be ensured that the subdirectory exists.

  • oFrameObj[out] Output frame object.

Returns:

False, if not successful (e.g. subdirectory does not exist). True, otherwise.

template<typename T, int l>
inline bool readFrame(const std::string &iFilename, Frame<T, l> &oFrameObj, const QDir &iSubdir)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters:

iSubdir[in] Subdirectory in which the file is to be stored. If subdirectory does not exists it is created before the file is stored.