Skip to content
This repository was archived by the owner on Feb 21, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/tools/recorder2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SET(SOURCE_FILES
pools/PoolsManager
buffer/RecorderInterface
pools/PoolPaths
)
pools/PoolWriteRGBD.cpp pools/PoolWriteRGBD.h pools/RecorderRGBD.cpp pools/RecorderRGBD.h buffer/ImageRingNode.cpp buffer/ImageRingNode.h buffer/RGBDRingNode.cpp buffer/RGBDRingNode.h recorder/Common.cpp recorder/Common.h)

add_definitions(-DGLADE_DIR="${gladedir}")

Expand Down Expand Up @@ -53,7 +53,8 @@ TARGET_LINK_LIBRARIES(recorder2
JderobotInterfaces
jderobotutil
ns
${resourcelocator_LIBRARIES}
${ZLIB_LIBRARIES}
${resourcelocator_LIBRARIES}
${GLOG_LIBRARIES}
)

Expand Down
41 changes: 41 additions & 0 deletions src/tools/recorder2/buffer/ImageRingNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Created by frivas on 21/05/17.

#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <opencv2/imgcodecs.hpp>
#include "ImageRingNode.h"
#include <logger/Logger.h>

namespace RingBufferNS {
void ImageRingNode::write(const std::string& logPath, const std::string &nameLog, std::vector<ImageRingNode> data2save) {
boost::posix_time::ptime init = boost::posix_time::microsec_clock::local_time();
std::stringstream root_path;
root_path << "data-" << nameLog << "/" << logPath << "/";
std::string jdeFile = root_path.str() + "cameraData2.jde";
std::ofstream myfile;
myfile.open (jdeFile);




for (auto it = data2save.begin(); it < data2save.end(); it++) {
std::stringstream path;
path << root_path.str() << it->relativeTime << ".png";
std::cout << "saving: " << path.str() << std::endl;
cv::imwrite(path.str(), it->frame, it->mCompression);
myfile << it->relativeTime << "/n";

std::cout << it->relativeTime << " to: " << jdeFile << std::endl;
}
myfile.close();
boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();

boost::posix_time::time_duration total = end - init;
LOG(INFO) << "Total milliseconds spent: " << total.total_milliseconds() << " - " << "Total Size: "
<< data2save.size() << std::endl;

for (auto it = data2save.begin(); it < data2save.end(); it++)
it->frame.release();
}

}
21 changes: 21 additions & 0 deletions src/tools/recorder2/buffer/ImageRingNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by frivas on 21/05/17.
//

#ifndef JDEROBOT_IMAGERINGNODE_H
#define JDEROBOT_IMAGERINGNODE_H

#include <opencv2/core/mat.hpp>

namespace RingBufferNS{
struct ImageRingNode {
static void write(const std::string& logPath, const std::string& nameLog, std::vector<RingBufferNS::ImageRingNode> data2save);

long long int relativeTime;
cv::Mat frame;
int cameraId;
std::vector<int> mCompression;
};
}

#endif //JDEROBOT_IMAGERINGNODE_H
47 changes: 47 additions & 0 deletions src/tools/recorder2/buffer/RGBDRingNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// Created by frivas on 21/05/17.
//

#include "RGBDRingNode.h"
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <opencv2/imgcodecs.hpp>
#include <logger/Logger.h>
#include <boost/algorithm/string/replace.hpp>


namespace RingBufferNS {

void RGBDRingNode::write(const std::string& logPath,const std::string &nameLog, std::vector<RingBufferNS::RGBDRingNode> data2save) {
boost::posix_time::ptime init = boost::posix_time::microsec_clock::local_time();
std::string root_path;
root_path = "data-" + nameLog + "/" + logPath + "/";

boost::replace_all(root_path, "./", "");
boost::replace_all(root_path, "//", "/");

// std::string jdeFile = root_path.str() + "cameraData2.jde";
// std::ofstream myfile;
// myfile.open (jdeFile);

for (auto it = data2save.begin(); it < data2save.end(); it++) {
std::stringstream pathRGB;
pathRGB << root_path << it->relativeTime << "rgb.png";
cv::imwrite(pathRGB.str(), it->rgb, it->mCompression);
std::stringstream pathDEPTH;
pathDEPTH << root_path << it->relativeTime << "depth.png";
cv::imwrite(pathDEPTH.str(), it->depth, it->mCompression);
}


boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();

boost::posix_time::time_duration total = end - init;
LOG(INFO) << "Total milliseconds spent: " << total.total_milliseconds() << " - " << "Total Size: "
<< data2save.size() << std::endl;

for (auto it = data2save.begin(); it < data2save.end(); it++) {
it->depth.release();
it->rgb.release();
}
}
}
24 changes: 24 additions & 0 deletions src/tools/recorder2/buffer/RGBDRingNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Created by frivas on 21/05/17.
//

#ifndef JDEROBOT_RGBDRINGNODE_H
#define JDEROBOT_RGBDRINGNODE_H

#include <opencv2/core/mat.hpp>

namespace RingBufferNS{
struct RGBDRingNode {
static void write(const std::string& logPath, const std::string& nameLog, std::vector<RingBufferNS::RGBDRingNode> data2save);

long long int relativeTime;
cv::Mat depth;
cv::Mat rgb;

int cameraId;
std::vector<int> mCompression;
};
}


#endif //JDEROBOT_RGBDRINGNODE_H
21 changes: 18 additions & 3 deletions src/tools/recorder2/buffer/RecorderInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,49 @@
// Created by frivas on 3/04/17.
//

#include <pools/PoolWriteRGBD.h>
#include <pools/PoolWriteImages.h>
#include "RecorderInterface.h"



namespace recorder {

RecorderInterface::RecorderInterface(std::vector<RecorderPoolPtr> &poolImages):
poolImages(poolImages)
RecorderInterface::RecorderInterface(PoolsManagerPtr& manager):
manager(manager)
{

}

bool RecorderInterface::saveLog(const ::std::string &name, ::Ice::Int seconds, const ::Ice::Current &ic)
{
bool ret = true;

auto poolImages=manager->getPoolsByType(IMAGES);
auto poolRGBD=manager->getPoolsByType(RGBD);

for (size_t i=0; i< poolImages.size(); i++)
{


poolWriteImagesPtr pool = boost::dynamic_pointer_cast<poolWriteImages> (poolImages[i]);
bool log = pool->startCustomLog(name, seconds);
ret = ret && log;
}

for (size_t i=0; i< poolRGBD.size(); i++)
{
PoolWriteRGBDPtr pool = boost::dynamic_pointer_cast<PoolWriteRGBD> (poolRGBD[i]);
bool log = pool->startCustomLog(name, seconds);
ret = ret && log;
}

return ret;
}

bool RecorderInterface::saveVideo(const ::std::string &path, const ::std::string &name, ::Ice::Int seconds,
const ::Ice::Current &ic) {
bool ret = true;
auto poolImages=manager->getPoolsByType(IMAGES);
for (size_t i = 0; i < poolImages.size(); i++) {
RecorderPoolPtr test;
poolWriteImagesPtr pool = boost::dynamic_pointer_cast<poolWriteImages> (poolImages[i]);
Expand Down
8 changes: 5 additions & 3 deletions src/tools/recorder2/buffer/RecorderInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@


#include <recorder.h>
#include <pools/PoolWriteImages.h>
#include <pools/PoolsManager.h>

namespace recorder {
class RecorderInterface : virtual public jderobot::recorder {
public:
RecorderInterface(std::vector<RecorderPoolPtr> &poolImages);
RecorderInterface(PoolsManagerPtr& manager);

virtual bool saveLog(const ::std::string &name, ::Ice::Int seconds, const ::Ice::Current &ic);

virtual bool
saveVideo(const ::std::string &path, const ::std::string &name, ::Ice::Int seconds, const ::Ice::Current &ic);

private:
std::vector<RecorderPoolPtr> &poolImages;
PoolsManagerPtr manager;


};

}
Expand Down
101 changes: 0 additions & 101 deletions src/tools/recorder2/buffer/RingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,105 +23,4 @@
namespace recorder
{

RingBuffer::RingBuffer(long int maxTime)
{
mMaxBufferTime = maxTime;
}

RingBuffer::~RingBuffer()
{

for (std::vector<RingNode>::iterator it = mBuffer.begin(); it < mBuffer.end(); it++ )
{
it->frame.release();
}

mBuffer.clear();
}

bool RingBuffer::addNode(RingNode node)
{

mBuffer.push_back(node);
return checkBuffer();
}

static void *write_thread(void* context){

((RingBuffer *)context)->write_th();

pthread_exit(NULL);
return NULL;
}

void RingBuffer::write_th()
{
boost::posix_time::ptime init = boost::posix_time::microsec_clock::local_time();
for (std::vector<RingNode>::iterator it = mWriteBuffer.begin(); it < mWriteBuffer.end(); it++ )
{
std::stringstream path;
path << "data-" << mNameLog << "/images/camera" << it->cameraId << "/" << it->relativeTime << ".png";
cv::imwrite(path.str(), it->frame, mCompression);
}
boost::posix_time::ptime end = boost::posix_time::microsec_clock::local_time();

boost::posix_time::time_duration total = end - init;
std::cout << "Total milliseconds spent: " << total.total_milliseconds() << " - " << "Total Size: " << mBuffer.size() << std::endl;

for (std::vector<RingNode>::iterator it = mWriteBuffer.begin(); it < mWriteBuffer.end(); it++ )
it->frame.release();


mWriteBuffer.clear();

}

void RingBuffer::write(std::string nameLog, std::vector<int> compression)
{
mCompression = compression;
mNameLog = nameLog;

mWriteBuffer.resize(mBuffer.size());
std::copy( mBuffer.begin(), mBuffer.end(), mWriteBuffer.begin() );

//std::cout << &(mBuffer[0].frame) << std::endl;
//std::cout << &(mWriteBuffer[0].frame) << std::endl;

pthread_attr_init(&mAttr);
pthread_attr_setdetachstate(&mAttr, PTHREAD_CREATE_JOINABLE);
pthread_create(&mThread, &mAttr, write_thread, this);


}

bool RingBuffer::checkBuffer()
{


for (std::vector<RingNode>::iterator it = mBuffer.begin(); it < mBuffer.end(); it++ )
{
std::vector<RingNode>::iterator newer = mBuffer.end()-1;
//jderobot::Logger::getInstance()->info("Current: " + boost::lexical_cast<std::string>(it->relativeTime) +
// " - Newer: " + boost::lexical_cast<std::string>(newer->relativeTime));


if ( ( newer->relativeTime - it->relativeTime) > mMaxBufferTime )
{
it->frame.release();
mBuffer.erase(it);
return true;
}
else
{
//jderobot::Logger::getInstance()->info("Older: " + boost::lexical_cast<std::string>(mBuffer.begin()->relativeTime) +
// " - Newer: " + boost::lexical_cast<std::string>((mBuffer.end()-1)->relativeTime));

return false;
}
}

return true;

}

}
Loading