2014-10-08 127 views
0

有没有一种方法可以使PCL库在等待一段时间后可视化点云?我有一系列的点云,并希望在PCLVisualizer中“通过更新单点云或在循环中显示+删除新的点云”来对它们进行“动画处理”。C++中的点云库(PCL)等待/延迟/休眠功能

我使用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忽略?)。

的waitKey也似乎在viewerOneOff功能与addPointCloud和removePointCloud用同样的方式像这样的时候被忽略(在函数结尾):

作品(仅显示):

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

你的代码中的任何地方都有spin()或spinOnce()方法吗?

viewer->spinOnce (100); 

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

+0

你说得对,这就是我正在寻找的。我试图使用CloudViewer类,但它似乎没有旋转/延迟方法,所以它在waitKey中表现得有点奇怪。人们必须切换到真正的spin/spinOnce的“大”PCLVisualizer类。 – Kozuch 2014-10-08 18:56:15