2011-06-05 14:45:39 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2010-2011, Mathieu Labbe and IntRoLab - Universite de Sherbrooke
|
|
|
|
|
*
|
|
|
|
|
* This file is part of RTAB-Map.
|
|
|
|
|
*
|
|
|
|
|
* RTAB-Map is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* RTAB-Map is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with RTAB-Map. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "rtabmap/core/RtabmapExp.h" // DLL export/import defines
|
|
|
|
|
|
|
|
|
|
#include <opencv2/highgui/highgui.hpp>
|
2012-06-24 17:19:34 +00:00
|
|
|
#include <opencv2/features2d/features2d.hpp>
|
|
|
|
|
#include <utilite/UThreadNode.h>
|
|
|
|
|
#include <utilite/UEventsHandler.h>
|
|
|
|
|
#include <utilite/UEvent.h>
|
|
|
|
|
#include <utilite/UDirectory.h>
|
|
|
|
|
#include <utilite/UTimer.h>
|
2011-06-05 14:45:39 +00:00
|
|
|
#include "rtabmap/core/Parameters.h"
|
2012-12-11 18:05:05 +00:00
|
|
|
#include "rtabmap/core/Features2d.h"
|
|
|
|
|
#include "rtabmap/core/Image.h"
|
2011-06-05 14:45:39 +00:00
|
|
|
#include <set>
|
|
|
|
|
#include <stack>
|
2012-03-03 01:46:30 +00:00
|
|
|
#include <list>
|
|
|
|
|
#include <vector>
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
namespace rtabmap
|
|
|
|
|
{
|
|
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
class CameraEvent :
|
|
|
|
|
public UEvent
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
|
|
|
|
public:
|
2012-06-24 17:19:34 +00:00
|
|
|
enum Code {
|
|
|
|
|
kCodeFeatures,
|
|
|
|
|
kCodeImage,
|
|
|
|
|
kCodeNoMoreImages
|
|
|
|
|
};
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
public:
|
2012-06-24 17:19:34 +00:00
|
|
|
CameraEvent(const cv::Mat & image, int cameraId = 0) :
|
|
|
|
|
UEvent(kCodeImage),
|
|
|
|
|
_cameraId(cameraId),
|
|
|
|
|
_image(image)
|
2011-06-05 14:45:39 +00:00
|
|
|
{
|
|
|
|
|
}
|
2012-06-24 17:19:34 +00:00
|
|
|
CameraEvent(const cv::Mat & descriptors, const std::vector<cv::KeyPoint> & keypoints, const cv::Mat & image = cv::Mat(), int cameraId = 0) :
|
|
|
|
|
UEvent(kCodeFeatures),
|
|
|
|
|
_cameraId(cameraId),
|
2013-01-21 18:55:25 +00:00
|
|
|
_image(image, 0, descriptors, keypoints)
|
2012-06-24 17:19:34 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CameraEvent(int cameraId = 0) :
|
|
|
|
|
UEvent(kCodeNoMoreImages),
|
|
|
|
|
_cameraId(cameraId)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cameraId() const {return _cameraId;}
|
|
|
|
|
|
|
|
|
|
// Image or descriptors
|
2012-12-11 18:05:05 +00:00
|
|
|
const Image & image() const {return _image;}
|
2012-06-24 17:19:34 +00:00
|
|
|
|
|
|
|
|
virtual ~CameraEvent() {}
|
|
|
|
|
virtual std::string getClassName() const {return std::string("CameraEvent");}
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
private:
|
2012-06-24 17:19:34 +00:00
|
|
|
int _cameraId;
|
2012-12-11 18:05:05 +00:00
|
|
|
Image _image;
|
2011-06-05 14:45:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Camera
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
class RTABMAP_EXP Camera :
|
|
|
|
|
public UThreadNode,
|
|
|
|
|
public UEventsHandler
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum State {kStateCapturing, kStateChangingParameters};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual ~Camera();
|
2012-06-24 17:19:34 +00:00
|
|
|
cv::Mat takeImage();
|
|
|
|
|
cv::Mat takeImage(cv::Mat & descriptors, std::vector<cv::KeyPoint> & keypoints);
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual bool init() = 0;
|
2012-06-26 19:23:43 +00:00
|
|
|
|
|
|
|
|
//getters
|
2011-06-05 14:45:39 +00:00
|
|
|
bool isPaused() const {return !this->isRunning();}
|
|
|
|
|
bool isCapturing() const {return this->isRunning();}
|
2012-06-26 19:23:43 +00:00
|
|
|
void getImageSize(unsigned int & width, unsigned int & height);
|
2012-06-24 17:19:34 +00:00
|
|
|
float getImageRate() const {return _imageRate;}
|
|
|
|
|
bool isFeaturesExtracted() const {return _featuresExtracted;}
|
2012-06-26 19:23:43 +00:00
|
|
|
|
|
|
|
|
//setters
|
|
|
|
|
void setFeaturesExtracted(bool featuresExtracted,
|
|
|
|
|
KeypointDetector::DetectorType detector = KeypointDetector::kDetectorUndef,
|
|
|
|
|
KeypointDescriptor::DescriptorType descriptor = KeypointDescriptor::kDescriptorUndef);
|
2012-03-03 01:46:30 +00:00
|
|
|
void setImageRate(float imageRate) {_imageRate = imageRate;}
|
|
|
|
|
void setAutoRestart(bool autoRestart) {_autoRestart = autoRestart;}
|
2012-06-26 19:23:43 +00:00
|
|
|
void setImageSize(unsigned int width, unsigned int height);
|
|
|
|
|
|
|
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
virtual void parseParameters(const ParametersMap & parameters);
|
|
|
|
|
int id() const {return _id;}
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*
|
|
|
|
|
* @param imageRate : image/second , 0 for fast as the camera can
|
|
|
|
|
*/
|
2012-06-24 17:19:34 +00:00
|
|
|
Camera(float imageRate = 0, bool autoRestart = false, unsigned int imageWidth = 0, unsigned int imageHeight = 0, unsigned int framesDropped = 0, int id = 0);
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
virtual void handleEvent(UEvent* anEvent);
|
2012-06-24 17:19:34 +00:00
|
|
|
virtual cv::Mat captureImage() = 0;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
private:
|
2012-06-24 17:19:34 +00:00
|
|
|
virtual void mainLoopBegin();
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual void mainLoop();
|
|
|
|
|
void process();
|
|
|
|
|
void pushNewState(State newState, const ParametersMap & parameters = ParametersMap());
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
float _imageRate;
|
|
|
|
|
int _id;
|
|
|
|
|
bool _autoRestart;
|
|
|
|
|
unsigned int _imageWidth;
|
|
|
|
|
unsigned int _imageHeight;
|
2012-06-24 17:19:34 +00:00
|
|
|
unsigned int _framesDropped;
|
|
|
|
|
UTimer _frameRateTimer;
|
2012-06-26 19:23:43 +00:00
|
|
|
UMutex _imageSizeMutex;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
UMutex _stateMutex;
|
|
|
|
|
std::stack<State> _state;
|
|
|
|
|
std::stack<ParametersMap> _stateParam;
|
2012-06-24 17:19:34 +00:00
|
|
|
|
|
|
|
|
bool _featuresExtracted;
|
|
|
|
|
KeypointDetector * _keypointDetector;
|
|
|
|
|
KeypointDescriptor * _keypointDescriptor;
|
2011-06-05 14:45:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////
|
|
|
|
|
// CameraImages
|
|
|
|
|
/////////////////////////
|
|
|
|
|
class RTABMAP_EXP CameraImages :
|
|
|
|
|
public Camera
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CameraImages(const std::string & path,
|
|
|
|
|
int startAt = 1,
|
|
|
|
|
bool refreshDir = false,
|
|
|
|
|
float imageRate = 0,
|
|
|
|
|
bool autoRestart = false,
|
|
|
|
|
unsigned int imageWidth = 0,
|
2012-06-24 17:19:34 +00:00
|
|
|
unsigned int imageHeight = 0,
|
|
|
|
|
unsigned int framesDropped = 0,
|
|
|
|
|
int id = 0);
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual ~CameraImages();
|
|
|
|
|
|
|
|
|
|
virtual bool init();
|
2012-06-26 19:23:43 +00:00
|
|
|
std::string getPath() const {return _path;}
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
protected:
|
|
|
|
|
virtual cv::Mat captureImage();
|
|
|
|
|
|
2011-06-05 14:45:39 +00:00
|
|
|
private:
|
|
|
|
|
std::string _path;
|
|
|
|
|
int _startAt;
|
|
|
|
|
// If the list of files in the directory is refreshed
|
|
|
|
|
// on each call of takeImage()
|
|
|
|
|
bool _refreshDir;
|
2012-06-24 17:19:34 +00:00
|
|
|
UDirectory _dir;
|
2011-06-05 14:45:39 +00:00
|
|
|
int _count;
|
|
|
|
|
std::string _lastFileName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////
|
|
|
|
|
// CameraVideo
|
|
|
|
|
/////////////////////////
|
|
|
|
|
class RTABMAP_EXP CameraVideo :
|
|
|
|
|
public Camera
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum Source{kVideoFile, kUsbDevice};
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
CameraVideo(int usbDevice = 0,
|
|
|
|
|
float imageRate = 0,
|
|
|
|
|
bool autoRestart = false,
|
|
|
|
|
unsigned int imageWidth = 0,
|
2012-06-24 17:19:34 +00:00
|
|
|
unsigned int imageHeight = 0,
|
|
|
|
|
unsigned int framesDropped = 0,
|
|
|
|
|
int id = 0);
|
2012-06-26 19:23:43 +00:00
|
|
|
CameraVideo(const std::string & filePath,
|
2011-06-05 14:45:39 +00:00
|
|
|
float imageRate = 0,
|
|
|
|
|
bool autoRestart = false,
|
|
|
|
|
unsigned int imageWidth = 0,
|
2012-06-24 17:19:34 +00:00
|
|
|
unsigned int imageHeight = 0,
|
|
|
|
|
unsigned int framesDropped = 0,
|
|
|
|
|
int id = 0);
|
2011-06-05 14:45:39 +00:00
|
|
|
virtual ~CameraVideo();
|
|
|
|
|
|
|
|
|
|
virtual bool init();
|
2012-06-26 19:23:43 +00:00
|
|
|
int getUsbDevice() const {return _usbDevice;}
|
|
|
|
|
const std::string & getFilePath() const {return _filePath;}
|
2012-06-24 17:19:34 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual cv::Mat captureImage();
|
2011-06-05 14:45:39 +00:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// File type
|
2012-06-26 19:23:43 +00:00
|
|
|
std::string _filePath;
|
2011-06-05 14:45:39 +00:00
|
|
|
|
2012-06-24 17:19:34 +00:00
|
|
|
cv::VideoCapture _capture;
|
2011-06-05 14:45:39 +00:00
|
|
|
Source _src;
|
|
|
|
|
|
|
|
|
|
// Usb camera
|
|
|
|
|
int _usbDevice;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace rtabmap
|