-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
174 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "Logger.h" | ||
|
||
#include <iostream> | ||
|
||
using std::cout; | ||
|
||
Logger::Logger(string outDir,std::shared_ptr<CameraInterface> cam) | ||
: | ||
doWrite(false), | ||
outDir(outDir), | ||
fileId(0), | ||
writeThread(nullptr), | ||
cam(cam) | ||
{ | ||
} | ||
|
||
Logger::~Logger() | ||
{ | ||
if(doWrite) | ||
{ | ||
stopWriting(); | ||
} | ||
} | ||
|
||
void Logger::startWriting() | ||
{ | ||
cout << "Starting writing.\n"; | ||
doWrite = true; | ||
nFrames = 0; | ||
|
||
string fn = outDir + "/seq" + std::to_string(fileId++) + ".klg"; | ||
file.open(fn,std::ios::binary); | ||
if(!file.is_open()) | ||
{ | ||
cout << "Could not open file: " << fn << "\n"; | ||
doWrite = false; | ||
return; | ||
} | ||
|
||
file.write((char*)&nFrames,sizeof(int32_t)); | ||
writeThread = new std::thread(&Logger::write,this); | ||
} | ||
|
||
void Logger::stopWriting() | ||
{ | ||
cout << "Stopping writing.\n"; | ||
doWrite = false; | ||
writeThread->join(); | ||
delete writeThread; | ||
writeThread = nullptr; | ||
|
||
file.seekp(0); | ||
file.write((char*)&nFrames,sizeof(int32_t)); | ||
|
||
file.close(); | ||
file.clear(); | ||
} | ||
|
||
void Logger::write() | ||
{ | ||
static int lastWrittenBufferIdx = -1; | ||
while(doWrite) | ||
{ | ||
std::this_thread::sleep_for(std::chrono::microseconds(1000)); | ||
|
||
int lastDepth = cam->latestDepthIndex; | ||
if(lastDepth == -1) | ||
continue; | ||
|
||
int bufferIdx = lastDepth % CameraInterface::numBuffers; | ||
if(bufferIdx == lastWrittenBufferIdx) | ||
continue; | ||
|
||
const void *depthData = cam->frameBuffers[bufferIdx].first.first; | ||
const void *rgbData = cam->frameBuffers[bufferIdx].first.second; | ||
|
||
int64_t currTimestamp = cam->frameBuffers[bufferIdx].second; | ||
int32_t depthSize = cam->width * cam->height * sizeof(uint16_t); | ||
int32_t rgbSize = cam->width * cam->height * 3 * sizeof(uint8_t); | ||
|
||
file.write((char*)&currTimestamp,sizeof(int64_t)); | ||
file.write((char*)&depthSize,sizeof(int32_t)); | ||
file.write((char*)&rgbSize,sizeof(int32_t)); | ||
file.write((char*)depthData,depthSize); | ||
file.write((char*)rgbData,rgbSize); | ||
|
||
lastWrittenBufferIdx = bufferIdx; | ||
nFrames++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <atomic> | ||
#include <memory> | ||
#include <cstdint> | ||
#include <fstream> | ||
#include <thread> | ||
|
||
#include "CameraInterface.h" | ||
|
||
using std::string; | ||
|
||
/** | ||
* Format is: | ||
* int32_t at file beginning for frame count | ||
* | ||
* For each frame: | ||
* int64_t: timestamp | ||
* int32_t: depthSize | ||
* int32_t: imageSize | ||
* depthSize * unsigned char: depth_compress_buf | ||
* imageSize * unsigned char: encodedImage->data.ptr | ||
*/ | ||
|
||
class Logger | ||
{ | ||
public: | ||
Logger(string outDir,std::shared_ptr<CameraInterface> cam); | ||
~Logger(); | ||
|
||
bool isWriting() const | ||
{ | ||
return doWrite; | ||
} | ||
|
||
void startWriting(); | ||
void stopWriting(); | ||
|
||
private: | ||
void write(); | ||
|
||
std::atomic<bool> doWrite; | ||
string outDir; | ||
int32_t nFrames; | ||
int fileId; | ||
std::ofstream file; | ||
std::thread *writeThread; | ||
std::shared_ptr<CameraInterface> cam; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
How to run: | ||
Press button R to start recording and press it again to stop. | ||
|
||
Dependencies: | ||
|
||
* librealsense | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters