Skip to content

Commit 36d8b86

Browse files
author
kaatrasa
committed
Fixes to cpp tools
1 parent 6c810ad commit 36d8b86

File tree

5 files changed

+46
-15
lines changed

5 files changed

+46
-15
lines changed

cpp/k4a/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,20 @@ endif()
3434

3535
set(TOOL_LIBS
3636
k4a::k4a
37-
spectacularAI::k4aPlugin)
37+
spectacularAI::k4aPlugin
38+
Threads::Threads)
3839

3940
# enables searching for dynamic libraries from the relative path ../lib
4041
if(NOT MSVC)
4142
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN/../lib:$ORIGIN/../lib/3rdparty'")
4243
endif()
4344

44-
add_executable(sai-k4a-record record.cpp)
45-
target_link_libraries(sai-k4a-record ${TOOL_LIBS})
45+
add_executable(sai-record-k4a record.cpp)
46+
target_link_libraries(sai-record-k4a ${TOOL_LIBS})
4647

4748
if(MSVC)
48-
add_custom_command(TARGET sai-k4a-record POST_BUILD
49-
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:sai-k4a-record> $<TARGET_FILE_DIR:sai-k4a-record>
49+
add_custom_command(TARGET sai-record-k4a POST_BUILD
50+
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_RUNTIME_DLLS:sai-record-k4a> $<TARGET_FILE_DIR:sai-record-k4a>
5051
COMMAND_EXPAND_LISTS
5152
)
5253
endif()

cpp/k4a/record.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ void showUsage() {
2020
<< " --vio_only (-useSlam=false)" << std::endl
2121
<< " --exposure <microseconds>" << std::endl
2222
<< " --whitebalance <kelvins>" << std::endl
23-
<< " --gain [0-255]" << std::endl
24-
<< " --brightness [0-255]" << std::endl
23+
<< " --gain <0-255>" << std::endl
24+
<< " --brightness <0-255>" << std::endl
2525
<< " --print" << std::endl
2626
<< std::endl;
2727
}
@@ -79,8 +79,10 @@ int main(int argc, char *argv[]) {
7979
}
8080

8181
// Require recording folder when using recording only mode.
82-
if (config.recordingOnly && config.recordingFolder.empty())
83-
fatal_error("Record only but recording folder is not set!");
82+
if (config.recordingOnly && config.recordingFolder.empty()) {
83+
std::cerr << "Record only but recording folder is not set!" << std::endl;
84+
return EXIT_FAILURE;
85+
}
8486

8587
// In monocular mode, disable depth camera.
8688
if (!config.useStereo) depthMode = K4A_DEPTH_MODE_OFF;

cpp/orbbec/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ endif()
3333

3434
set(TOOL_LIBS
3535
${OrbbecSDK_LIBS}
36-
spectacularAI::orbbecPlugin)
36+
spectacularAI::orbbecPlugin
37+
Threads::Threads)
3738

3839
# enables searching for dynamic libraries from the relative path ../lib
3940
if(NOT MSVC)

cpp/realsense/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ else()
1515
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
1616
endif()
1717

18+
find_package(Threads REQUIRED)
1819
find_package(realsense2 REQUIRED)
1920
find_package(spectacularAI_realsensePlugin REQUIRED)
2021

2122
set(TOOL_LIBS
2223
realsense2::realsense2
23-
spectacularAI::realsensePlugin)
24+
spectacularAI::realsensePlugin
25+
Threads::Threads)
2426

2527
# enables searching for dynamic libraries from the relative path ../lib
2628
if(NOT MSVC)

cpp/realsense/record.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#include <atomic>
2+
#include <thread>
3+
#include <vector>
14
#include <iostream>
25
#include <librealsense2/rs.hpp>
36
#include <spectacularAI/realsense/plugin.hpp>
@@ -17,6 +20,7 @@ void showUsage() {
1720
<< " --saturation <value>" << std::endl
1821
<< " --sharpness <value>" << std::endl
1922
<< " --white_balance <value>" << std::endl
23+
<< " --print" << std::endl
2024
<< std::endl;
2125
}
2226

@@ -35,6 +39,7 @@ struct ColorCameraConfig {
3539
int main(int argc, char** argv) {
3640
spectacularAI::rsPlugin::Configuration config;
3741
ColorCameraConfig colorConfig;
42+
bool print = false;
3843

3944
std::vector<std::string> arguments(argv, argv + argc);
4045
for (size_t i = 1; i < arguments.size(); ++i) {
@@ -63,6 +68,8 @@ int main(int argc, char** argv) {
6368
colorConfig.sharpness = std::stoi(arguments.at(++i));
6469
else if (argument == "--white_balance")
6570
colorConfig.whiteBalance = std::stoi(arguments.at(++i));
71+
else if (argument == "--print")
72+
print = true;
6673
else if (argument == "--help" || argument == "-h") {
6774
showUsage();
6875
return EXIT_SUCCESS;
@@ -112,13 +119,31 @@ int main(int argc, char** argv) {
112119
// Start pipeline
113120
rs2::config rsConfig;
114121
vioPipeline.configureStreams(rsConfig);
115-
auto vioSession = vioPipeline.startSession(rsConfig);
122+
auto session = vioPipeline.startSession(rsConfig);
116123

117-
std::cout << "Recording, use Ctrl+C to stop" << std::endl;
124+
std::atomic<bool> shouldQuit(false);
125+
std::thread inputThread([&]() {
126+
std::cout << "Press Enter to quit." << std::endl << std::endl;
127+
getchar();
128+
shouldQuit = true;
129+
});
118130

119-
while (true) {
120-
vioSession->waitForOutput();
131+
while (!shouldQuit) {
132+
if (session->hasOutput()) {
133+
auto out = session->getOutput();
134+
if (print) {
135+
std::cout << "Vio API pose: " << out->pose.time << ", " << out->pose.position.x
136+
<< ", " << out->pose.position.y << ", " << out->pose.position.z << ", "
137+
<< out->pose.orientation.x << ", " << out->pose.orientation.y << ", "
138+
<< out->pose.orientation.z << ", " << out->pose.orientation.w
139+
<< std::endl;
140+
}
141+
}
142+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
121143
}
122144

145+
std::cout << "Exiting." << std::endl;
146+
if (shouldQuit) inputThread.join();
147+
123148
return 0;
124149
}

0 commit comments

Comments
 (0)