簡體   English   中英

我如何從點雲獲取RGB值

[英]How can I get rgb value from point cloud

我有點雲。 我想獲取其RGB值。 我怎樣才能做到這一點?
為了使我的問題更清楚,請參閱代碼。

// Load the first input file into a PointCloud<T> with an appropriate type : 
        pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGB>);
        if (pcl::io::loadPCDFile<pcl::PointXYZRGB> ("../data/station1.pcd", *cloud1) == -1)
        {
            std::cout << "Error reading PCD file !!!" << std::endl;
            exit(-1);
        }

我想獨自獲得每個價值

std::cout << " x = " << cloud1->points[11].x << std::endl;
std::cout << " y = " << cloud1->points[11].y << std::endl;
std::cout << " z = " << cloud1->points[11].z << std::endl;
std::cout << " r = " << cloud1->points[11].r << std::endl;
std::cout << " g = " << cloud1->points[11].g << std::endl;
std::cout << " b = " << cloud1->points[11].b << std::endl;

但是結果是我得到了這樣的東西:

 x = 2.33672
 y = 3.8102
 z = 8.86153
 r = �
 g = w
 b = �

從點雲文檔來看

表示歐幾里得xyz坐標和RGB顏色的點結構。

由於歷史原因(PCL最初是作為ROS包開發的), RGB信息被打包為整數並轉換為浮點數。 這是我們希望在不久的將來刪除的內容,但是與此同時,以下代碼段應幫助您在PointXYZRGB結構中打包和解壓縮RGB顏色:

// pack r/g/b into rgb
uint8_t r = 255, g = 0, b = 0;    // Example: Red color
uint32_t rgb = ((uint32_t)r << 16 | (uint32_t)g << 8 | (uint32_t)b);
p.rgb = *reinterpret_cast<float*>(&rgb);

要將數據解壓縮為單獨的值,請使用:

PointXYZRGB p;
// unpack rgb into r/g/b
uint32_t rgb = *reinterpret_cast<int*>(&p.rgb);
uint8_t r = (rgb >> 16) & 0x0000ff;
uint8_t g = (rgb >> 8)  & 0x0000ff;
uint8_t b = (rgb)       & 0x0000ff;

另外,從1.1.0開始,您可以直接使用pr,pg和pb。

文件point_types.hpp的559行的定義。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM