Skip to content

Commit

Permalink
Fix null-terminated character handling.
Browse files Browse the repository at this point in the history
Benchmark current saving time:

./saveRealSenseData
Acquisition time, mean=33.1679 ms ; median=32.2727 ms ; std=13.2707 ms
FPS, mean=30.1497 fps ; median=30.9859 fps

./saveRealSenseData -s -c
Acquisition time, mean=127.668 ms ; median=124.821 ms ; std=19.3663 ms
FPS, mean=7.83282 fps ; median=8.01145 fps

./saveRealSenseData -s -c -i
Acquisition time, mean=128.93 ms ; median=130.964 ms ; std=21.1411 ms
FPS, mean=7.75615 fps ; median=7.63572 fps

./saveRealSenseData -s -c -i -d
Acquisition time, mean=129.049 ms ; median=126.479 ms ; std=19.2512 ms
FPS, mean=7.74902 fps ; median=7.90642 fps

./saveRealSenseData -s -c -i -d -p
Acquisition time, mean=128.407 ms ; median=126.213 ms ; std=14.4955 ms
FPS, mean=7.78771 fps ; median=7.92311 fps
  • Loading branch information
s-trinh committed May 10, 2024
1 parent e46bd34 commit e4afdf1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
24 changes: 20 additions & 4 deletions example/device/framegrabber/saveRealSenseData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ int main(int argc, const char *argv[])
#else
std::vector<vpColVector> pointCloud;
#endif
std::vector<double> vec_delta_time;
while (!quit) {
double start = vpTime::measureTimeMs();
if (use_aligned_stream) {
#ifdef USE_REALSENSE2
#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
Expand Down Expand Up @@ -697,10 +699,6 @@ int main(int argc, const char *argv[])
vpDisplay::displayText(I_color, 20, 20, ss.str(), vpColor::red);
}

vpDisplay::flush(I_color);
vpDisplay::flush(I_depth);
vpDisplay::flush(I_infrared);

if (save && !click_to_save) {
#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_COMMON)
pcl::PointCloud<pcl::PointXYZ>::Ptr pointCloud_copy = pointCloud->makeShared();
Expand All @@ -710,6 +708,16 @@ int main(int argc, const char *argv[])
#endif
}

double delta_time = vpTime::measureTimeMs() - start;
vec_delta_time.push_back(delta_time);
std::ostringstream oss_time;
oss_time << delta_time << " ms ; fps=" << 1000/delta_time;
vpDisplay::displayText(I_color, 40, 20, oss_time.str(), vpColor::red);

vpDisplay::flush(I_color);
vpDisplay::flush(I_depth);
vpDisplay::flush(I_infrared);

vpMouseButton::vpMouseButtonType button;
if (vpDisplay::getClick(I_color, button, false)) {
if (!click_to_save) {
Expand Down Expand Up @@ -741,6 +749,14 @@ int main(int argc, const char *argv[])
}
}

double mean_vec_delta_time = vpMath::getMean(vec_delta_time);
double median_vec_delta_time = vpMath::getMedian(vec_delta_time);
double std_vec_delta_time = vpMath::getStdev(vec_delta_time);
std::cout << "Acquisition time, mean=" << mean_vec_delta_time << " ms ; median="
<< median_vec_delta_time << " ms ; std=" << std_vec_delta_time << " ms" << std::endl;
std::cout << "FPS, mean=" << 1000/mean_vec_delta_time << " fps ; median="
<< 1000/median_vec_delta_time << " fps" << std::endl;

storage_thread.join();

return EXIT_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ int main(int argc, char *argv[])
std::cout << "Color mode? " << (channel > 1) << std::endl;

visp::cnpy::NpyArray arr_camera_name = npz_data["camera_name"];
const std::string camera_name = std::string(arr_camera_name.data<char>());
// For null-terminated character handling, see:
// https://stackoverflow.com/a/8247804
// https://stackoverflow.com/a/45491652
std::vector<char> vec_arr_camera_name = arr_camera_name.as_vec<char>();
const std::string camera_name = std::string(vec_arr_camera_name.begin(), vec_arr_camera_name.end());
std::cout << "Camera name: " << camera_name << std::endl;

visp::cnpy::NpyArray arr_px = npz_data["cam_px"];
Expand Down

0 comments on commit e4afdf1

Please sign in to comment.