【问题标题】:Point Cloud Library (PCL) wait/delay/sleep function in C++C++ 中的点云库 (PCL) 等待/延迟/睡眠功能
【发布时间】:2014-10-08 10:23:38
【问题描述】:

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

我正在使用 C++ 并设置了 CloudViewer example。到目前为止,我只能通过与 OpenCV 交叉编译并使用它的 waitKey(milliseconds) 函数来达到一定程度的延迟。我在 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})

我将不胜感激。

【问题讨论】:

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


    【解决方案1】:

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

    viewer->spinOnce (100);
    

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

    【讨论】:

    • 你说得对,这就是我要找的。我试图使用 CloudViewer 类,但它似乎没有自旋/延迟方法,所以它在使用 waitKey 时表现得有点奇怪。必须切换到真正的 spin/spinOnce 的“大”PCLVisualizer 类。
    猜你喜欢
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-03
    • 2012-04-02
    • 2014-04-15
    • 1970-01-01
    相关资源
    最近更新 更多