2015-12-02 174 views
2

我下面這個教程類PCLVisualizer官方PCL文檔中:PCL展臺例如:無法獲得鍵盤和鼠標事件

http://pointclouds.org/documentation/tutorials/pcl_visualizer.php

,我有與鍵盤收購的煩惱:當我選擇渲染窗口,其中顯示的點雲,並嘗試按「R」或「q」,沒有任何反應,當我嘗試按下鼠標左鍵,會顯示以下文字:

Left mouse button released at position (413, 475)

及以下引發錯誤(在運行時):

Assertion failed: (px != 0), function operator->, file /usr/local/include/boost/smart_ptr/shared_ptr.hpp, line 687. 
Abort trap: 6 

我看到這種類型的錯誤發生在你不變量的聲明初始化boost::shared_ptr。但是在文檔中列出的代碼中,變量已經定義好了,所以我想這個問題涉及到庫,或者它不是?

我搜索在互聯網上的一個解決方案,但我沒有發現任何可能解決這一問題。

是否存在有人認爲是能夠獲取按鍵的點雲的通過在OS X上運行它提供窗口?

如果問題不明確,請告訴我。 非常感謝您的幫助或信息!

+0

我試圖**初始化變量'viewer'的主要功能**和鼠標的收購工作:'提高:: shared_ptr的查看器(新PCL ::可視化: :PCLVisualizer(「3D Viewer」));',在我看來斷言失敗了,因爲傳遞給回調'mouseEventOccured()'的指針沒有正確初始化。但**鍵盤採集**仍然**不起作用**。 – Mauro

回答

1

你不顯示任何代碼,所以很難說你的程序有什麼問題。

這裏是一個工作示例,與PCL最新幹線(VTK幹線)在Ubuntu 14.04測試:

#include <iostream> 
#include <pcl/visualization/pcl_visualizer.h> 

void keyboardEventOccurred(const pcl::visualization::KeyboardEvent &event, void* viewer_void) 
{ 
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void); 
    if (event.getKeySym() == "r" && event.keyDown()) 
    std::cout << "'r' was pressed" << std::endl; 
    if (event.getKeySym() == "h" && event.keyDown()) 
    std::cout << "'h' was pressed" << std::endl; 
} 

void mouseEventOccurred(const pcl::visualization::MouseEvent &event, void* viewer_void) 
{ 
    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer = *static_cast<boost::shared_ptr<pcl::visualization::PCLVisualizer> *>(viewer_void); 

    if (event.getButton() == pcl::visualization::MouseEvent::LeftButton && 
     event.getType() == pcl::visualization::MouseEvent::MouseButtonRelease) 
    std::cout << "Left mouse button released at position (" << event.getX() << ", " << event.getY() << ")" << std::endl; 
} 

int main() 
{ 
    pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer); 
    viewer->addCoordinateSystem(); 
    viewer->registerKeyboardCallback(keyboardEventOccurred, (void*)&viewer); 
    viewer->registerMouseCallback(mouseEventOccurred, (void*)&viewer); 
    viewer->spin(); 
} 

注意一些關鍵筆劃已使用的PCL可視化的一些行動(按h爲更多細節),但它並不妨礙你使用它們。

+0

我在我的電腦上試過了你的代碼,但鍵盤採集仍然無法工作。我點擊了pointcloud的渲染窗口,使它成爲焦點,並且我嘗試推送'r'和'h':這些鍵永遠不會被'keyboardEventOccurred'函數捕獲,並且它們被我用來運行程序。我也試圖改變按鍵,但沒有改變。我正在** OS X El Capitan **上運行程序,也許這是一個OS X問題。無論如何,感謝您的幫助。 – Mauro

+0

我在官方bug跟蹤器上報告了這個問題:https://github.com/PointCloudLibrary/pcl/issues/1465 –

相關問題