[Jderobot-admin] jderobot-r1237 - in trunk/src/stable: components/recorder interfaces/slice/jderobot
rocapal en jderobot.org
rocapal en jderobot.org
Mar Jun 24 20:13:14 CEST 2014
Author: rocapal
Date: 2014-06-24 20:13:14 +0200 (Tue, 24 Jun 2014)
New Revision: 1237
Modified:
trunk/src/stable/components/recorder/poolWriteImages.cpp
trunk/src/stable/components/recorder/poolWriteImages.h
trunk/src/stable/components/recorder/recorder.cfg
trunk/src/stable/components/recorder/recorder.cpp
trunk/src/stable/interfaces/slice/jderobot/recorder.ice
Log:
#276 Added record video through ICE interface
Modified: trunk/src/stable/components/recorder/poolWriteImages.cpp
===================================================================
--- trunk/src/stable/components/recorder/poolWriteImages.cpp 2014-05-29 11:34:31 UTC (rev 1236)
+++ trunk/src/stable/components/recorder/poolWriteImages.cpp 2014-06-24 18:13:14 UTC (rev 1237)
@@ -9,7 +9,7 @@
#include <libgen.h>
namespace recorder{
-poolWriteImages::poolWriteImages(jderobot::CameraPrx prx, int freq, int poolSize, int cameraID, std::string imageFormat, std::vector<int> compression_params, MODE mode, int bufferSeconds) {
+poolWriteImages::poolWriteImages(jderobot::CameraPrx prx, int freq, int poolSize, int cameraID, std::string imageFormat, std::vector<int> compression_params, MODE mode, int bufferSeconds, std::string videoMode) {
// TODO Auto-generated constructor stub
pthread_mutex_init(&(this->mutex), NULL);
pthread_mutex_init(&(this->mModeMutex), NULL);
@@ -27,6 +27,7 @@
mBuffer = NULL;
mLastSecondsLog = 5;
mNameLog = "alarm1";
+ mVideoMode = videoMode;
if (mMode == SAVE_BUFFER)
{
@@ -34,6 +35,7 @@
mBuffer = new RingBuffer(mBufferSeconds*1000);
}
+ mCamType = this->prx->getImageData()->description->format;
std::stringstream filePath;
filePath << "data/images/camera" << this->cameraID << "/cameraData.jde";
@@ -52,6 +54,13 @@
return this->active;
}
+bool poolWriteImages::startCustomVideo(std::string path, std::string name, int seconds)
+{
+ mNamePathVideo = path;
+ return startCustomLog(name, seconds);
+}
+
+
bool poolWriteImages::startCustomLog (std::string name, int seconds)
{
bool ret;
@@ -116,12 +125,40 @@
else
{
// Save buffer in memory mode == SAVE_BUFFER
+ cv::Mat saveImage;
+ if (mVideoMode.compare("Video")==0)
+ {
+ if (mCamType.compare("RGB8")==0)
+ {
+ saveImage.create(img2Save.size(), CV_8UC3);
+ cv::cvtColor(img2Save,saveImage,CV_BGR2RGB);
+ }
+ else if (mCamType.compare("DEPTH8_16")==0)
+ {
+ saveImage.create(img2Save.size(), CV_8UC3);
+ std::vector<cv::Mat> layers;
+ cv::split(img2Save, layers);
+ cv::cvtColor(layers[0],saveImage,CV_GRAY2RGB);
+
+ }
+ else
+ {
+ jderobot::Logger::getInstance()->warning("mCamType not recognized " + mCamType);
+ }
+ }
+ else if (mVideoMode.compare("Log")==0)
+ {
+ saveImage.create(img2Save.size(), img2Save.type());
+ img2Save.copyTo(saveImage);
+ }
+
+
RingBuffer::RingNode node;
node.cameraId = cameraID;
node.relativeTime = relative;
- img2Save.copyTo(node.frame);
+ saveImage.copyTo(node.frame);
mBuffer->addNode(node);
if (currentMode == WRITE_BUFFER)
@@ -186,6 +223,32 @@
this->logfile.close();
jderobot::Logger::getInstance()->info("End recording log: " + mNameLog );
+ // Save the video
+ if (mVideoMode.compare("Video")==0)
+ {
+ std::stringstream basePath, fileData, fileImage, command, command_video, fileVideo, tmpFileVideo;
+ basePath << "data-" << mNameLog << "/images/camera" << this->cameraID << "/";
+ fileData << basePath.str() << "cameraData.jde";
+ fileImage << basePath.str() << "list.txt";
+
+ command << "cat " << fileData.str() << " | sed -e 's/$/.png/g' > " << fileImage.str();
+
+ system(command.str().c_str());
+
+ fileVideo << mNamePathVideo << "/" << mNameLog << "-" << this->cameraID << "-" << mCamType << ".avi";
+ tmpFileVideo << mNamePathVideo << "/" << mNameLog << "-" << this->cameraID << "-" << mCamType << ".mp4";
+
+ command_video << "cd " << basePath.str() << ";" ;
+ command_video << "mencoder mf://@list.txt -mf w=320:h=240:fps=10:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o " << tmpFileVideo.str() << ";" ;
+ command_video << "ffmpeg -y -i " << tmpFileVideo.str() << " -vcodec libx264 " << fileVideo.str() << ";" ;
+ command_video << "rm -f " << tmpFileVideo.str() << ";" ;
+ command_video << "cd -; rm -rf " << "data-" << mNameLog;
+
+ std::cout << command_video.str() << std::endl;
+
+ system(command_video.str().c_str());
+ }
+
pthread_mutex_lock(&(this->mModeMutex));
mMode = SAVE_BUFFER;
pthread_mutex_unlock(&(this->mModeMutex));
@@ -194,7 +257,7 @@
{
std::stringstream path;
path << "data-" << mNameLog << "/images/camera" << cameraID << "/" << relative << "." << imageFormat;
- cv::imwrite(path.str(), img2Save,this->compression_params);
+ cv::imwrite(path.str(), saveImage ,this->compression_params);
}
}
}
Modified: trunk/src/stable/components/recorder/poolWriteImages.h
===================================================================
--- trunk/src/stable/components/recorder/poolWriteImages.h 2014-05-29 11:34:31 UTC (rev 1236)
+++ trunk/src/stable/components/recorder/poolWriteImages.h 2014-06-24 18:13:14 UTC (rev 1237)
@@ -50,7 +50,7 @@
WRITE_END_LOG
};
- poolWriteImages(jderobot::CameraPrx prx, int freq, int poolSize, int cameraID, std::string imageFormat, std::vector<int> compression_params, MODE mode, int bufferSeconds);
+ poolWriteImages(jderobot::CameraPrx prx, int freq, int poolSize, int cameraID, std::string imageFormat, std::vector<int> compression_params, MODE mode, int bufferSeconds, std::string videoMode);
virtual ~poolWriteImages();
bool getActive();
//void produceImage(cv::Mat image, long long int it);
@@ -58,6 +58,7 @@
void producer_thread( struct timeval inicio);
bool startCustomLog(std::string name, int seconds);
+ bool startCustomVideo(std::string path, std::string name, int seconds);
@@ -84,8 +85,11 @@
int mBufferSeconds;
MODE mMode;
+ std::string mNamePathVideo;
boost::posix_time::ptime mFinalInit, mFinalEnd;
std::ofstream logfile;
+ std::string mVideoMode;
+ std::string mCamType;
//threads
Modified: trunk/src/stable/components/recorder/recorder.cfg
===================================================================
--- trunk/src/stable/components/recorder/recorder.cfg 2014-05-29 11:34:31 UTC (rev 1236)
+++ trunk/src/stable/components/recorder/recorder.cfg 2014-06-24 18:13:14 UTC (rev 1237)
@@ -32,7 +32,9 @@
# Config to buffer mode
Recorder.Buffer.Enabled=0
-Recorder.Buffer.Seconds=60
+Recorder.Buffer.Seconds=30
+# Mode = Log or Video
+Recorder.Buffer.Mode=Video
Recorder.Endpoints=default -h 0.0.0.0 -p 9992
Recorder.Name=Recorder-Log
Modified: trunk/src/stable/components/recorder/recorder.cpp
===================================================================
--- trunk/src/stable/components/recorder/recorder.cpp 2014-05-29 11:34:31 UTC (rev 1236)
+++ trunk/src/stable/components/recorder/recorder.cpp 2014-06-24 18:13:14 UTC (rev 1237)
@@ -273,6 +273,18 @@
return ret;
}
+
+ virtual bool saveVideo(const ::std::string& path, const ::std::string& name, ::Ice::Int seconds, const ::Ice::Current& ic )
+ {
+ bool ret = true;
+ for (int i=0; i< poolImages.size(); i++)
+ {
+ bool log = poolImages[i]->startCustomVideo(path, name, seconds);
+ ret = ret && log;
+ }
+
+ return ret;
+ }
};
@@ -400,6 +412,7 @@
int bufferEnabled = prop->getPropertyAsIntWithDefault("Recorder.Buffer.Enabled",0);
int bufferSeconds = prop->getPropertyAsIntWithDefault("Recorder.Buffer.Seconds",0);
+ std::string videoMode = prop->getProperty("Recorder.Buffer.Mode");
for (int i=0; i< nCameras; i++){
struct stat buf;
@@ -428,7 +441,7 @@
//pool
recorder::poolWriteImages *temp = new recorder::poolWriteImages(cprxAux, Hz,poolSize,i+1,imageFormat,
- compression_params, (bufferEnabled == 0)? recorder::poolWriteImages::WRITE_FRAME : recorder::poolWriteImages::SAVE_BUFFER, bufferSeconds);
+ compression_params, (bufferEnabled == 0)? recorder::poolWriteImages::WRITE_FRAME : recorder::poolWriteImages::SAVE_BUFFER, bufferSeconds, videoMode);
poolImages.push_back(temp);
Modified: trunk/src/stable/interfaces/slice/jderobot/recorder.ice
===================================================================
--- trunk/src/stable/interfaces/slice/jderobot/recorder.ice 2014-05-29 11:34:31 UTC (rev 1236)
+++ trunk/src/stable/interfaces/slice/jderobot/recorder.ice 2014-06-24 18:13:14 UTC (rev 1237)
@@ -26,6 +26,7 @@
interface recorder{
bool saveLog (string name, int seconds);
+ bool saveVideo (string path, string name, int seconds);
};
};
More information about the Jderobot-admin
mailing list