2
2
#include < iostream>
3
3
#include < thread>
4
4
#include < vector>
5
+ #include < sstream>
6
+ #include < iomanip>
7
+ #include < chrono>
8
+ #include < filesystem>
5
9
#include < k4a/k4a.h>
6
10
#include < k4a/k4atypes.h>
7
11
#include < spectacularAI/k4a/plugin.hpp>
8
12
9
13
void showUsage () {
10
14
std::cout << " Supported arguments:" << std::endl
11
15
<< " -h, --help Help" << std::endl
12
- << " --output <recording_folder>, recorded output" << std::endl
16
+ << " --output <recording_folder>, otherwise recording is saved to current working directory" << std::endl
17
+ << " --auto_subfolders, create timestamp-named subfolders for each recording" << std::endl
13
18
<< " --recording_only, disables Vio" << std::endl
14
19
<< " --color_res <720p, 1080p, 1440p, 1536p, 2160p, 3070p>" << std::endl
15
20
<< " --depth_mode <1 (NVOF_2X2BINNED), 2 (NVOF_UNBINNED), 3 (WFOV_2X2BINNED), 4 (WFOV_UNBINNED)>" << std::endl
@@ -26,6 +31,18 @@ void showUsage() {
26
31
<< std::endl;
27
32
}
28
33
34
+ void setAutoSubfolder (std::string &recordingFolder) {
35
+ auto now = std::chrono::system_clock::now ();
36
+ auto timePoint = std::chrono::system_clock::to_time_t (now);
37
+ std::tm localTime = *std::localtime (&timePoint);
38
+ std::ostringstream oss;
39
+ oss << std::put_time (&localTime, " %Y-%m-%d_%H-%M-%S" );
40
+ std::filesystem::path basePath = recordingFolder;
41
+ std::filesystem::path filename = oss.str ();
42
+ std::filesystem::path combinedPath = basePath / filename;
43
+ recordingFolder = combinedPath.string ();
44
+ }
45
+
29
46
int main (int argc, char *argv[]) {
30
47
std::vector<std::string> arguments (argv, argv + argc);
31
48
std::string colorResolution = " 720p" ;
@@ -37,11 +54,14 @@ int main(int argc, char *argv[]) {
37
54
int32_t brightness = -1 ;
38
55
spectacularAI::k4aPlugin::Configuration config;
39
56
bool print = false ;
57
+ bool autoSubfolders = false ;
40
58
41
59
for (size_t i = 1 ; i < arguments.size (); ++i) {
42
60
const std::string &argument = arguments.at (i);
43
61
if (argument == " --output" )
44
62
config.recordingFolder = arguments.at (++i);
63
+ else if (argument == " --auto_subfolders" )
64
+ autoSubfolders = true ;
45
65
else if (argument == " --recording_only" )
46
66
config.recordingOnly = true ;
47
67
else if (argument == " --color_res" )
@@ -78,12 +98,15 @@ int main(int argc, char *argv[]) {
78
98
}
79
99
}
80
100
81
- // Require recording folder when using recording only mode.
82
- if (config.recordingOnly && config. recordingFolder .empty ()) {
83
- std::cerr << " Record only but recording folder is not set! " << std::endl ;
84
- return EXIT_FAILURE ;
101
+ // Set default recording folder if user didn't specify output
102
+ if (config.recordingFolder .empty ()) {
103
+ autoSubfolders = true ;
104
+ config. recordingFolder = " data " ;
85
105
}
86
106
107
+ // Create timestamp-named subfolders for each recording
108
+ if (autoSubfolders) setAutoSubfolder (config.recordingFolder );
109
+
87
110
// In monocular mode, disable depth camera.
88
111
if (!config.useStereo ) depthMode = K4A_DEPTH_MODE_OFF;
89
112
@@ -171,6 +194,7 @@ int main(int argc, char *argv[]) {
171
194
172
195
std::atomic<bool > shouldQuit (false );
173
196
std::thread inputThread ([&]() {
197
+ std::cout << " Recording to '" << config.recordingFolder << " '" << std::endl;
174
198
std::cout << " Press Enter to quit." << std::endl << std::endl;
175
199
getchar ();
176
200
shouldQuit = true ;
0 commit comments