C++中的点云库(PCL)等待/延迟/睡眠功能

Point Cloud Library (PCL) wait/delay/sleep function in C++

本文关键字:等待 延迟 功能 PCL C++      更新时间:2023-10-16

在可视化点云时,有没有办法让PCL库等待一段时间?我有一系列的点云,希望在PCLVisualizer中"动画化"这些点云(通过更新单个点云或在循环中显示+删除新的点云)。

我使用的是C++,并且已经设置了CloudViewer示例。到目前为止,我只能通过与OpenCV交叉编译并使用其waitKey(毫秒)函数来达到一定程度的延迟。我使用的是Ubuntu 14.04 LTS。以OpenCV:为例

#include <opencv2/opencv.hpp>
using namespace cv;

然而,waitKey只能在viewerPsycho函数的最后简单使用,它确实会延迟该函数中的计数器:

void viewerPsycho (pcl::visualization::PCLVisualizer& viewer)
{
    static unsigned count = 0;
    std::stringstream ss;
    ss << "Once per viewer loop: " << count++;
    viewer.removeShape ("text", 0);
    viewer.addText (ss.str(), 200, 300, "text", 0);
    // this will delay counter but shows nothing
    waitKey(1000);
    viewer.addPointCloud(point_cloud_ptr, "first");
    waitKey(1000);
    viewer.removePointCloud("first");
}

我的代码比原始示例更丰富,并且addPointCloud方法在不尝试延迟的情况下可以正常工作。方法removePointCloud可能也起作用,因为没有显示任何内容(waitKey已忽略?)。

在viewerOneOff函数中,当以与addPointCloud和removePointCloud相同的方式使用时,waitKey似乎也会被忽略,如下所示(在函数末尾):

作品(仅展示):

viewer.addPointCloud(point_cloud_ptr, "first");

不工作(什么都不显示):

viewer.addPointCloud(point_cloud_ptr, "first");
waitKey(5000);
viewer.removePointCloud("first");

我的CMakeLists.txt:

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(opencv_pcl)
find_package(PCL 1.2 REQUIRED)
find_package(OpenCV REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (opencv_pcl opencv_pcl.cpp)    
target_link_libraries (opencv_pcl ${PCL_LIBRARIES} ${OpenCV_LIBS})

我将感谢任何帮助。

您的代码中有spin()或spinOnce()方法吗?

viewer->spinOnce (100);

这将更新渲染器并处理所有交互(http://docs.pointclouds.org/trunk/classpcl_1_1visualization_1_1_p_c_l_visualizer.html#a896556f91ba6b45b12a9543a2b397193)。