/*
* 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 .
*/
#include "utilite/ULogger.h"
#include "utilite/UTimer.h"
#include "utilite/UDirectory.h"
#include "utilite/UConversion.h"
#include "rtabmap/core/Camera.h"
#include "utilite/UEventsManager.h"
#include "utilite/UEventsHandler.h"
#include
#include
#include
void showUsage()
{
printf("Usage:\n"
"webcamCapture [option]\n"
" -device #: Id of the webcam (default 0)\n"
" -width #: Image width (default 640)\n"
" -height #: Image height (default 480)\n"
" -fps #.#: Frame rate (Hz) (default 2.0)\n"
" -hide : Image not shown while capturing (default true)\n"
" -dir \"path\": Path of the images saved (default \"./imagesCaptured\")\n"
" -save : Save images captured (default true)\n"
" -startId #: Image id to start with (default 1)\n"
" -ext \"ext\": Image extension (default \"jpg\")\n"
" -debug: Debug trace\n");
exit(1);
}
class ImagesHandler : public UEventsHandler
{
public:
ImagesHandler(const std::string & targetDir, const std::string & ext, int startId, bool show, bool save) :
targetDir_(targetDir),
ext_(ext),
startId_(startId),
show_(show),
save_(save),
id_(startId)
{
if(show_)
{
cv::namedWindow("Webcam", CV_WINDOW_AUTOSIZE);
}
}
virtual ~ImagesHandler()
{
if(show_)
{
cv::destroyWindow("Webcam");
}
}
protected:
virtual void handleEvent(UEvent * e)
{
if(e->getClassName().compare("SMStateEvent") == 0)
{
const rtabmap::CameraEvent * event = (const rtabmap::CameraEvent*)e;
cv::Mat image = event->image();
if(!image.empty())
{
if(show_)
{
cv::imshow("Webcam", image);
}
if(save_)
{
std::string fileName = targetDir_ + "/";
fileName += uNumber2Str(id_++);
fileName += ".";
fileName += ext_;
cv::imwrite(fileName, image);
printf("Image %s saved!\n", fileName.c_str());
}
}
else
{
printf("Image is null?!?\n");
}
}
}
private:
std::string targetDir_;
std::string ext_;
int startId_;
bool show_;
bool save_;
int id_;
};
int main(int argc, char * argv[])
{
bool show = true;
int usbDevice = 0;
int imageWidth = 640;
int imageHeight = 480;
float imageRate = 2.0;
int startId = 1;
std::string extension = "jpg";
bool save = false;
std::string targetDirectory = UDirectory::currentDir(true) + "imagesCaptured";
for(int i=1; i 100)
{
showUsage();
}
++i;
}
if(strcmp(argv[i], "-width") == 0 && i+1