mirror of
https://github.com/introlab/rtabmap.git
synced 2026-09-02 01:20:25 +08:00
Camera: added some getters and protected image size modification
git-svn-id: http://rtabmap.googlecode.com/svn/trunk/rtabmap@574 f169173b-cf89-36c8-b27e-44dbe73f0c83
This commit is contained in:
@@ -103,15 +103,23 @@ public:
|
|||||||
cv::Mat takeImage();
|
cv::Mat takeImage();
|
||||||
cv::Mat takeImage(cv::Mat & descriptors, std::vector<cv::KeyPoint> & keypoints);
|
cv::Mat takeImage(cv::Mat & descriptors, std::vector<cv::KeyPoint> & keypoints);
|
||||||
virtual bool init() = 0;
|
virtual bool init() = 0;
|
||||||
|
|
||||||
|
//getters
|
||||||
bool isPaused() const {return !this->isRunning();}
|
bool isPaused() const {return !this->isRunning();}
|
||||||
bool isCapturing() const {return this->isRunning();}
|
bool isCapturing() const {return this->isRunning();}
|
||||||
unsigned int getImageWidth() const {return _imageWidth;}
|
void getImageSize(unsigned int & width, unsigned int & height);
|
||||||
unsigned int getImageHeight() const {return _imageHeight;}
|
|
||||||
float getImageRate() const {return _imageRate;}
|
float getImageRate() const {return _imageRate;}
|
||||||
bool isFeaturesExtracted() const {return _featuresExtracted;}
|
bool isFeaturesExtracted() const {return _featuresExtracted;}
|
||||||
void setFeaturesExtracted(bool featuresExtracted, KeypointDetector::DetectorType detector = KeypointDetector::kDetectorUndef, KeypointDescriptor::DescriptorType descriptor = KeypointDescriptor::kDescriptorUndef);
|
|
||||||
|
//setters
|
||||||
|
void setFeaturesExtracted(bool featuresExtracted,
|
||||||
|
KeypointDetector::DetectorType detector = KeypointDetector::kDetectorUndef,
|
||||||
|
KeypointDescriptor::DescriptorType descriptor = KeypointDescriptor::kDescriptorUndef);
|
||||||
void setImageRate(float imageRate) {_imageRate = imageRate;}
|
void setImageRate(float imageRate) {_imageRate = imageRate;}
|
||||||
void setAutoRestart(bool autoRestart) {_autoRestart = autoRestart;}
|
void setAutoRestart(bool autoRestart) {_autoRestart = autoRestart;}
|
||||||
|
void setImageSize(unsigned int width, unsigned int height);
|
||||||
|
|
||||||
|
|
||||||
virtual void parseParameters(const ParametersMap & parameters);
|
virtual void parseParameters(const ParametersMap & parameters);
|
||||||
int id() const {return _id;}
|
int id() const {return _id;}
|
||||||
|
|
||||||
@@ -140,6 +148,7 @@ private:
|
|||||||
unsigned int _imageHeight;
|
unsigned int _imageHeight;
|
||||||
unsigned int _framesDropped;
|
unsigned int _framesDropped;
|
||||||
UTimer _frameRateTimer;
|
UTimer _frameRateTimer;
|
||||||
|
UMutex _imageSizeMutex;
|
||||||
|
|
||||||
UMutex _stateMutex;
|
UMutex _stateMutex;
|
||||||
std::stack<State> _state;
|
std::stack<State> _state;
|
||||||
@@ -171,6 +180,7 @@ public:
|
|||||||
virtual ~CameraImages();
|
virtual ~CameraImages();
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
|
std::string getPath() const {return _path;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual cv::Mat captureImage();
|
virtual cv::Mat captureImage();
|
||||||
@@ -209,7 +219,7 @@ public:
|
|||||||
unsigned int imageHeight = 0,
|
unsigned int imageHeight = 0,
|
||||||
unsigned int framesDropped = 0,
|
unsigned int framesDropped = 0,
|
||||||
int id = 0);
|
int id = 0);
|
||||||
CameraVideo(const std::string & fileName,
|
CameraVideo(const std::string & filePath,
|
||||||
float imageRate = 0,
|
float imageRate = 0,
|
||||||
bool autoRestart = false,
|
bool autoRestart = false,
|
||||||
unsigned int imageWidth = 0,
|
unsigned int imageWidth = 0,
|
||||||
@@ -219,14 +229,15 @@ public:
|
|||||||
virtual ~CameraVideo();
|
virtual ~CameraVideo();
|
||||||
|
|
||||||
virtual bool init();
|
virtual bool init();
|
||||||
int getUsbDevice() {return _usbDevice;}
|
int getUsbDevice() const {return _usbDevice;}
|
||||||
|
const std::string & getFilePath() const {return _filePath;}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual cv::Mat captureImage();
|
virtual cv::Mat captureImage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// File type
|
// File type
|
||||||
std::string _fileName;
|
std::string _filePath;
|
||||||
|
|
||||||
cv::VideoCapture _capture;
|
cv::VideoCapture _capture;
|
||||||
Source _src;
|
Source _src;
|
||||||
|
|||||||
@@ -78,6 +78,26 @@ void Camera::setFeaturesExtracted(bool featuresExtracted, KeypointDetector::Dete
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Camera::setImageSize(unsigned int width, unsigned int height)
|
||||||
|
{
|
||||||
|
_imageSizeMutex.lock();
|
||||||
|
{
|
||||||
|
_imageWidth = width;
|
||||||
|
_imageHeight = height;
|
||||||
|
}
|
||||||
|
_imageSizeMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Camera::getImageSize(unsigned int & width, unsigned int & height)
|
||||||
|
{
|
||||||
|
_imageSizeMutex.lock();
|
||||||
|
{
|
||||||
|
width = _imageWidth;
|
||||||
|
height = _imageHeight;
|
||||||
|
}
|
||||||
|
_imageSizeMutex.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void Camera::parseParameters(const ParametersMap & parameters)
|
void Camera::parseParameters(const ParametersMap & parameters)
|
||||||
{
|
{
|
||||||
UDEBUG("");
|
UDEBUG("");
|
||||||
@@ -262,17 +282,18 @@ cv::Mat Camera::takeImage(cv::Mat & descriptors, std::vector<cv::KeyPoint> & key
|
|||||||
UTimer timer;
|
UTimer timer;
|
||||||
img = this->captureImage();
|
img = this->captureImage();
|
||||||
UDEBUG("Time capturing image = %fs", timer.ticks());
|
UDEBUG("Time capturing image = %fs", timer.ticks());
|
||||||
if(img.depth() != CV_8U)
|
|
||||||
{
|
|
||||||
UWARN("Images should have already 8U depth !?");
|
|
||||||
cv::Mat tmp = img;
|
|
||||||
img = cv::Mat();
|
|
||||||
tmp.convertTo(img, CV_8U);
|
|
||||||
UDEBUG("Time converting image to 8U = %fs", timer.ticks());
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!img.empty())
|
if(!img.empty())
|
||||||
{
|
{
|
||||||
|
if(img.depth() != CV_8U)
|
||||||
|
{
|
||||||
|
UWARN("Images should have already 8U depth !?");
|
||||||
|
cv::Mat tmp = img;
|
||||||
|
img = cv::Mat();
|
||||||
|
tmp.convertTo(img, CV_8U);
|
||||||
|
UDEBUG("Time converting image to 8U = %fs", timer.ticks());
|
||||||
|
}
|
||||||
|
|
||||||
if(_featuresExtracted && _keypointDetector && _keypointDescriptor)
|
if(_featuresExtracted && _keypointDetector && _keypointDescriptor)
|
||||||
{
|
{
|
||||||
keypoints = _keypointDetector->generateKeypoints(img);
|
keypoints = _keypointDetector->generateKeypoints(img);
|
||||||
@@ -424,6 +445,8 @@ cv::Mat CameraImages::captureImage()
|
|||||||
#else
|
#else
|
||||||
img = cv::imread(fullPath.c_str(), -1);
|
img = cv::imread(fullPath.c_str(), -1);
|
||||||
#endif
|
#endif
|
||||||
|
UDEBUG("width=%d, height=%d, channels=%d, elementSize=%d, total=%d", img.cols, img.rows, img.channels(), img.elemSize(), img.total());
|
||||||
|
|
||||||
// FIXME : it seems that some png are incorrectly loaded with opencv c++ interface, where c interface works...
|
// FIXME : it seems that some png are incorrectly loaded with opencv c++ interface, where c interface works...
|
||||||
if(img.depth() != CV_8U)
|
if(img.depth() != CV_8U)
|
||||||
{
|
{
|
||||||
@@ -442,17 +465,21 @@ cv::Mat CameraImages::captureImage()
|
|||||||
UWARN("Directory is not set, camera must be initialized.");
|
UWARN("Directory is not set, camera must be initialized.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int w;
|
||||||
|
unsigned int h;
|
||||||
|
this->getImageSize(w, h);
|
||||||
|
|
||||||
if(!img.empty() &&
|
if(!img.empty() &&
|
||||||
getImageWidth() &&
|
w &&
|
||||||
getImageHeight() &&
|
h &&
|
||||||
getImageWidth() != (unsigned int)img.cols &&
|
w != (unsigned int)img.cols &&
|
||||||
getImageHeight() != (unsigned int)img.rows)
|
h != (unsigned int)img.rows)
|
||||||
{
|
{
|
||||||
cv::Mat resampled;
|
cv::Mat resampled;
|
||||||
cv::resize(img, resampled, cv::Size(getImageWidth(), getImageHeight()));
|
cv::resize(img, resampled, cv::Size(w, h));
|
||||||
img = resampled;
|
img = resampled;
|
||||||
}
|
}
|
||||||
UDEBUG("");
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +502,7 @@ CameraVideo::CameraVideo(int usbDevice,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CameraVideo::CameraVideo(const std::string & fileName,
|
CameraVideo::CameraVideo(const std::string & filePath,
|
||||||
float imageRate,
|
float imageRate,
|
||||||
bool autoRestart,
|
bool autoRestart,
|
||||||
unsigned int imageWidth,
|
unsigned int imageWidth,
|
||||||
@@ -483,7 +510,7 @@ CameraVideo::CameraVideo(const std::string & fileName,
|
|||||||
unsigned int framesDropped,
|
unsigned int framesDropped,
|
||||||
int id) :
|
int id) :
|
||||||
Camera(imageRate, autoRestart, imageWidth, imageHeight, framesDropped, id),
|
Camera(imageRate, autoRestart, imageWidth, imageHeight, framesDropped, id),
|
||||||
_fileName(fileName),
|
_filePath(filePath),
|
||||||
_src(kVideoFile)
|
_src(kVideoFile)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -503,18 +530,23 @@ bool CameraVideo::init()
|
|||||||
|
|
||||||
if(_src == kUsbDevice)
|
if(_src == kUsbDevice)
|
||||||
{
|
{
|
||||||
ULOGGER_DEBUG("CameraVideo::init() Usb device initialization on device %d with imgSize=[%d,%d]", _usbDevice, getImageWidth(), getImageHeight());
|
unsigned int w;
|
||||||
|
unsigned int h;
|
||||||
|
this->getImageSize(w, h);
|
||||||
|
|
||||||
|
ULOGGER_DEBUG("CameraVideo::init() Usb device initialization on device %d with imgSize=[%d,%d]", _usbDevice, w, h);
|
||||||
_capture.open(_usbDevice);
|
_capture.open(_usbDevice);
|
||||||
if(getImageWidth() && getImageHeight())
|
|
||||||
|
if(w && h)
|
||||||
{
|
{
|
||||||
_capture.set(CV_CAP_PROP_FRAME_WIDTH, double(getImageWidth()));
|
_capture.set(CV_CAP_PROP_FRAME_WIDTH, double(w));
|
||||||
_capture.set(CV_CAP_PROP_FRAME_HEIGHT, double(getImageHeight()));
|
_capture.set(CV_CAP_PROP_FRAME_HEIGHT, double(h));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(_src == kVideoFile)
|
else if(_src == kVideoFile)
|
||||||
{
|
{
|
||||||
ULOGGER_DEBUG("Camera: filename=\"%s\"", _fileName.c_str());
|
ULOGGER_DEBUG("Camera: filename=\"%s\"", _filePath.c_str());
|
||||||
_capture.open(_fileName.c_str());
|
_capture.open(_filePath.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -541,14 +573,18 @@ cv::Mat CameraVideo::captureImage()
|
|||||||
ULOGGER_WARN("The camera must be initialized before requesting an image.");
|
ULOGGER_WARN("The camera must be initialized before requesting an image.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int w;
|
||||||
|
unsigned int h;
|
||||||
|
this->getImageSize(w, h);
|
||||||
|
|
||||||
if(!img.empty() &&
|
if(!img.empty() &&
|
||||||
getImageWidth() &&
|
w &&
|
||||||
getImageHeight() &&
|
h &&
|
||||||
getImageWidth() != (unsigned int)img.cols &&
|
w != (unsigned int)img.cols &&
|
||||||
getImageHeight() != (unsigned int)img.rows)
|
h != (unsigned int)img.rows)
|
||||||
{
|
{
|
||||||
cv::Mat resampled;
|
cv::Mat resampled;
|
||||||
cv::resize(img, resampled, cv::Size(getImageWidth(), getImageHeight()));
|
cv::resize(img, resampled, cv::Size(w, h));
|
||||||
return resampled;
|
return resampled;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user