1. 程式人生 > >PCL 視覺化

PCL 視覺化

視覺化(visualization)是利用計算機圖形學和影象處理技術,將資料轉換影象在螢幕上顯示出來,並進行互動處理的的理論,方法和技術,

pcl_visualization庫建立了能夠快速建立原型的目的和視覺化演算法對三維點雲資料操作的結果。類似於opencv的highgui例程顯示二維影象,在螢幕上繪製基本的二維圖形,庫提供了以下幾點:

(1)渲染和設定視覺特性的方法(如顏色、大小、透明度等)在PCL任意n維的點雲資料集pcl::PointCloud<T> format

                          

(2)在螢幕上繪製基本的3D形狀的方法(例如,圓柱體,球體,線,多邊形等),無論是從點集或引數方程;

                        

(3)一個直方圖視覺化模組(pclhistogramvisualizer)的二維圖;

                     

(4)大量的幾何和顏色處理pcl::PointCloud<T> datasets

                   

                       .

1.   class  pcl::visualization::CloudViewer   類CloudViewer實現建立點雲視覺化的視窗,以及相關的視覺化功能

Public Member Functions

CloudViewer (const std::string &window_name)   構建視覺化點雲視窗,視窗名為window_name
void  showCloud (const ColorCloud::ConstPtr &cloud, const std::string &cloudname="cloud")
視覺化視窗顯示cloud對應的點雲,考慮到多個點雲用鍵值cloudname來限定是哪一個點雲
bool  wasStopped (int millis_to_wait=1)
判斷使用者是否已經關閉視窗,如果是則需要登出視窗
在視窗執行期間處理x的回撥函式,key為鍵值標識此回撥函式,知道視窗關閉
值呼叫回撥函式一次
刪除key對應的回撥函式
註冊鍵盤事件回撥函式,cookie為回撥時的引數,callback為回撥函式的指標
template<typename T >
boost::signals2::connection 
同上,其中的instance 指向是實現該回到函式的物件

(2)太多了這裡就貼出所有的關於視覺化的類    對於類的成員就不再一一介紹

  等等*****************************************8

應用例項

cloud_viewer.cpp:

#include <pcl/visualization/cloud_viewer.h>   //類cloud_viewer標頭檔案申明
#include <iostream>                           //標準輸入輸出標頭檔案申明
#include <pcl/io/io.h>                        //I/O相關標頭檔案申明
#include <pcl/io/pcd_io.h>                    //PCD檔案讀取
    

/**********************************************************************************
  函式是作為回撥函式,在主函式中只註冊一次 ,函式實現對視覺化物件背景顏色的設定,新增一個圓球幾何體
*********************************************************************************/
int user_data;
    
void 
viewerOneOff (pcl::visualization::PCLVisualizer& viewer)
{
    viewer.setBackgroundColor (1.0, 0.5, 1.0);       //設定背景顏色
    pcl::PointXYZ o;                                  //儲存球的圓心位置
    o.x = 1.0;
    o.y = 0;
    o.z = 0;
    viewer.addSphere (o, 0.25, "sphere", 0);                  //新增圓球幾何物件
    std::cout << "i only run once" << std::endl;
    
}
   /***********************************************************************************
   作為回撥函式,在主函式中註冊後每幀顯示都執行一次,函式具體實現在視覺化物件中新增一個重新整理顯示字串
   *************************************************************************************/ 
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);
    
    //FIXME: possible race condition here:
    user_data++;
}
  /**************************************************************
  首先載入點雲檔案到點雲物件,並初始化視覺化物件viewer,註冊上面的回
   調函式,執行迴圈直到收到關閉viewer的訊息退出程式
   *************************************************************/  
int 
main ()
{
    pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>);    //宣告cloud 
    pcl::io::loadPCDFile ("my_point_cloud.pcd", *cloud);         //載入點雲檔案
    
    pcl::visualization::CloudViewer viewer("Cloud Viewer");      //建立viewer物件
    
    //showCloud函式是同步的,在此處等待直到渲染顯示為止
    viewer.showCloud(cloud);
    
    //該註冊函式在視覺化的時候只執行一次
    viewer.runOnVisualizationThreadOnce (viewerOneOff);
    
    //該註冊函式在渲染輸出時每次都呼叫
    viewer.runOnVisualizationThread (viewerPsycho);
    while (!viewer.wasStopped ())
    {
    //此處可以新增其他處理
    //FIXME: Note that this is running in a separate thread from viewerPsycho
    //and you should guard against race conditions yourself...
    user_data++;
    }
    return 0;
}

編譯結果如下

 

未完待續*************************8888888