GSLAM  3.0.0
Public Types | Public Member Functions | Protected Attributes | List of all members
Dataset Class Reference

The Dataset class. More...

Inheritance diagram for Dataset:
GObject

Public Types

typedef std::vector< std::string > StrVec
 

Public Member Functions

 Dataset (const std::string &dataset)
 
std::string name () const
 
virtual std::string type () const
 
virtual bool isOpened ()
 
virtual FramePtr grabFrame ()
 
virtual bool open (const std::string &dataset)
 
virtual bool isLive () const
 
- Public Member Functions inherited from GObject
virtual void call (const std::string &command, void *arg=NULL)
 
virtual void draw ()
 
virtual bool toByteArray (std::vector< uchar > &array)
 
virtual bool fromByteArray (std::vector< uchar > &array)
 

Protected Attributes

std::string _name
 
DatasetPtr _impl
 

Detailed Description

The Dataset class.

Here is a little demo to implement an OpenCV monocular Dataset

#include <opencv2/opencv.hpp>
#include <GSLAM/core/GSLAM.h>
using namespace GSLAM;
using namespace std;
class DatasetOpenCVMono : public GSLAM::Dataset
{
public:
DatasetOpenCVMono(){}
virtual std::string type() const{return "DatasetOpenCVMono";}
virtual bool open(const std::string& dataset){
var.parseFile(dataset.c_str());
if(!video.open(var.get<std::string>("video","")) return false;
camera=Camera(var.get<std::vector<double>>("camera_paras",{}));
if(!camera.isValid()) return false;
_name=dataset;
frameId=1;
return true;
}
virtual bool isOpened(){return video.isOpened()&&camera.isValid();}
virtual FramePtr grabFrame(){
double timestamp=GSLAM::TicToc::timestamp();
cv::Mat img;
video>>img;
return FramePtr(new FrameMono(frameId++,timestamp,gimg,camera,IMAGE_BGRA));
}
GSLAM::FrameID frameId;
cv::VideoCapture video;
GSLAM::Camera camera;
};
GSLAM_REGISTER_DATASET(DatasetOpenCVMono,cvmono)

Compile this file as a shared library with name "gslamDB_cvmono", or compile this file along with the excutable file. It would be very easy to use the dataset:

Dataset dataset("file_path.cvmono");
if(dataset.isOpened())
auto fr=dataset.grabFrame();// obtain a frame