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

时间:2014-10-08 10:23:39

标签: c++ delay sleep wait point-cloud-library

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

我正在使用C ++并设置了CloudViewer example。到目前为止,我只能通过使用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被忽略?)。

当使用与addPointCloud相同的方式并且像这样使用removePointCloud时,在viewerOneOff函数中似乎也忽略了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})

我将不胜感激。

1 个答案:

答案 0 :(得分:1)

你的代码中是否有spin()或spinOnce()方法?

viewer->spinOnce (100);

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

相关问题