Skip to content

Commit 09b3d39

Browse files
committed
Saving the frame index instead of the timestamp for the video saving.
The timestamp is saved anyway
1 parent d2dd3e4 commit 09b3d39

1 file changed

Lines changed: 27 additions & 20 deletions

File tree

devices/YarpRobotLoggerDevice/src/YarpRobotLoggerDevice.cpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ bool BipedalLocomotion::YarpRobotLoggerDevice::prepareCameraLogging()
13331333
}
13341334
ok = m_bufferManager.addChannel({"camera::" + camera + "::rgb",
13351335
{1, 1}, //
1336-
{"timestamp"}});
1336+
{"frame_index"}});
13371337
if (!ok)
13381338
{
13391339
log()->error("{} Unable to add the channel for the camera named {}.",
@@ -1402,12 +1402,12 @@ bool BipedalLocomotion::YarpRobotLoggerDevice::prepareCameraLogging()
14021402

14031403
ok = m_bufferManager.addChannel({"camera::" + camera + "::rgb",
14041404
{1, 1}, //
1405-
{"timestamp"}});
1405+
{"frame_index"}});
14061406

14071407
ok = ok
14081408
&& m_bufferManager.addChannel({"camera::" + camera + "::depth",
14091409
{1, 1}, //
1410-
{"timestamp"}});
1410+
{"frame_index"}});
14111411

14121412
if (!ok)
14131413
{
@@ -1466,7 +1466,7 @@ bool BipedalLocomotion::YarpRobotLoggerDevice::prepareExogenousImageLogging()
14661466
}
14671467
ok = m_bufferManager.addChannel({"exogenous_images::" + signal.signalName + "::rgb",
14681468
{1, 1}, //
1469-
{"timestamp"}});
1469+
{"frame_index"}});
14701470

14711471
if (!ok)
14721472
{
@@ -1889,17 +1889,17 @@ void YarpRobotLoggerDevice::recordVideo(const std::string& cameraName, VideoWrit
18891889
{
18901890
assert(writer.rgb->saveMode == VideoWriter::SaveMode::Frame);
18911891

1892+
unsigned int frameIndex = writer.frameIndex.load();
18921893
const std::filesystem::path imgPath
1893-
= writer.rgb->framesPath
1894-
/ ("img_" + std::to_string(writer.frameIndex) + ".png");
1894+
= writer.rgb->framesPath / ("img_" + std::to_string(frameIndex) + ".png");
18951895

18961896
cv::imwrite(imgPath.string(), writer.rgb->frame);
18971897

18981898
// lock the the buffered manager mutex
18991899
std::lock_guard lock(m_bufferManagerMutex);
19001900

19011901
// TODO here we may save the frame itself
1902-
m_bufferManager.push_back(std::chrono::duration<double>(time).count(),
1902+
m_bufferManager.push_back(frameIndex,
19031903
std::chrono::duration<double>(time).count(),
19041904
"camera::" + cameraName + "::rgb");
19051905
}
@@ -1936,9 +1936,9 @@ void YarpRobotLoggerDevice::recordVideo(const std::string& cameraName, VideoWrit
19361936
{
19371937
assert(writer.depth->saveMode == VideoWriter::SaveMode::Frame);
19381938

1939+
unsigned int frameIndex = writer.frameIndex.load();
19391940
const std::filesystem::path imgPath
1940-
= writer.depth->framesPath
1941-
/ ("img_" + std::to_string(writer.frameIndex) + ".png");
1941+
= writer.depth->framesPath / ("img_" + std::to_string(frameIndex) + ".png");
19421942

19431943
// convert the image into 16bit grayscale image
19441944
cv::Mat image16Bit;
@@ -1949,7 +1949,7 @@ void YarpRobotLoggerDevice::recordVideo(const std::string& cameraName, VideoWrit
19491949
std::lock_guard lock(m_bufferManagerMutex);
19501950

19511951
// TODO here we may save the frame itself
1952-
m_bufferManager.push_back(std::chrono::duration<double>(time).count(),
1952+
m_bufferManager.push_back(frameIndex,
19531953
std::chrono::duration<double>(time).count(),
19541954
"camera::" + cameraName + "::depth");
19551955
}
@@ -2032,21 +2032,22 @@ void YarpRobotLoggerDevice::saveExogenousImages(
20322032
// Lock the image saver mutex
20332033
std::lock_guard<std::mutex> imageLock(writer.rgb->mutex);
20342034

2035+
unsigned int frameIndex = writer.frameIndex.load();
20352036
// Save the frame
20362037
const std::filesystem::path imgPath
2037-
= m_exogenousImageWriters[signal.signalName].rgb->framesPath
2038-
/ ("img_"
2039-
+ std::to_string(m_exogenousImageWriters[signal.signalName].frameIndex++)
2038+
= writer.rgb->framesPath
2039+
/ ("img_" + std::to_string(frameIndex)
20402040
+ ".png");
20412041
cv::imwrite(imgPath.string(), colorImg);
20422042

20432043
// lock the the buffered manager mutex
20442044
std::lock_guard bufferLock(m_bufferManagerMutex);
20452045

20462046
// TODO here we may save the frame itself
2047-
m_bufferManager.push_back(std::chrono::duration<double>(time).count(),
2047+
m_bufferManager.push_back(frameIndex,
20482048
std::chrono::duration<double>(time).count(),
20492049
"exogenous_images::" + signal.signalName + "::rgb");
2050+
writer.frameIndex++;
20502051
}
20512052
}
20522053
}
@@ -2853,7 +2854,7 @@ void BipedalLocomotion::YarpRobotLoggerDevice::waitForVideoThreadsToPause()
28532854
allPaused = true;
28542855
for (auto& [cameraName, writer] : m_videoWriters)
28552856
{
2856-
if (!writer.paused)
2857+
if (writer.recordVideoIsRunning && !writer.paused)
28572858
{
28582859
allPaused = false;
28592860
break;
@@ -2863,7 +2864,7 @@ void BipedalLocomotion::YarpRobotLoggerDevice::waitForVideoThreadsToPause()
28632864
{
28642865
for (auto& [cameraName, writer] : m_exogenousImageWriters)
28652866
{
2866-
if (!writer.paused)
2867+
if (writer.recordVideoIsRunning && !writer.paused)
28672868
{
28682869
allPaused = false;
28692870
break;
@@ -2880,13 +2881,19 @@ void BipedalLocomotion::YarpRobotLoggerDevice::resumeVideoThreads()
28802881
{
28812882
for (auto& [cameraName, writer] : m_videoWriters)
28822883
{
2883-
writer.requestPause = false;
2884-
writer.paused = false;
2884+
if (writer.recordVideoIsRunning)
2885+
{
2886+
writer.requestPause = false;
2887+
writer.paused = false;
2888+
}
28852889
}
28862890
for (auto& [cameraName, writer] : m_exogenousImageWriters)
28872891
{
2888-
writer.requestPause = false;
2889-
writer.paused = false;
2892+
if (writer.recordVideoIsRunning)
2893+
{
2894+
writer.requestPause = false;
2895+
writer.paused = false;
2896+
}
28902897
}
28912898
log()->info("[YarpRobotLoggerDevice::resumeVideoThreads] Resumed video threads.");
28922899
}

0 commit comments

Comments
 (0)