2015-02-11 311 views
0

我必須使用點雲庫訪問點雲中點的顏色屬性。任何幫助表示讚賞。如何從點雲中獲取顏色信息並顯示它?

當前我正在使用它來顯示雲。但它只顯示紅色藍色綠色,而不是對象的實際顏色。

boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (
    new pcl::visualization::PCLVisualizer ("3D Viewer") 
); 

viewer->setBackgroundColor (0, 0, 0); 
pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud); 
viewer->addPointCloud<pcl::PointXYZRGB> (cloud, rgb, "sample cloud"); 
viewer->setPointCloudRenderingProperties (
     pcl::visualization::PCL_VISUALIZER_POINT_SIZE 
    , 3 
    , "sample cloud" 
); 

viewer->addCoordinateSystem (1.0); 
viewer->initCameraParameters(); 
+0

代碼是正確的,但在這種情況下設置顏色處理程序是多餘的。使用'viewer-> addPointCloud(雲,「樣本雲」)將點雲添加到可視化器中應該足夠了;' – taketwo 2015-02-12 15:14:40

+0

如果我取出顏色處理器,則雲的顏色只是白色。 – RoboticsNovice 2015-02-16 11:57:15

回答

0

您的代碼對我來說似乎沒問題,您如何設置雲的顏色?

pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>); 

pcl::PointXYZRGB point; 

// ... 

uint32_t rgb = (static_cast<uint32_t>(255) << 16 | 
       static_cast<uint32_t>(15) << 8 | 
       static_cast<uint32_t>(15)); 

point.rgb = *reinterpret_cast<float*>(&rgb); 

point_cloud_ptr->points.push_back(point); 
+0

可以單獨訪問顏色通道:'point.r = 255; point.g = 15; point.b = 15;',從而避免顯式轉換和投射。 – taketwo 2015-02-12 15:16:24

+0

哪個PCL版本? r/g/b的範圍是多少?你有沒有嘗試過移位/施放方法? – Kornel 2015-02-12 15:22:39

+0

不幸的是,我不能告訴你在哪個版本中引入了這個版本,但是很久以前。我記得2012年夏天使用'r','g'和'b'。範圍是'[0..255]'。 – taketwo 2015-02-12 15:43:49

相關問題