简体   繁体   English

我如何从点云获取RGB值

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

I have a point-cloud. 我有点云。 I want to get its RGB value. 我想获取其RGB值。 How can I do that? 我怎样才能做到这一点?
To make my question clearer, please see the codes. 为了使我的问题更清楚,请参阅代码。

// 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);
        }

I want to get each value alone 我想独自获得每个价值

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;

But as a result I get something like that : 但是结果是我得到了这样的东西:

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

From the point cloud docs : 从点云文档来看

A point structure representing Euclidean xyz coordinates, and the RGB color. 表示欧几里得xyz坐标和RGB颜色的点结构。

Due to historical reasons (PCL was first developed as a ROS package), the RGB information is packed into an integer and casted to a float. 由于历史原因(PCL最初是作为ROS包开发的), RGB信息被打包为整数并转换为浮点数。 This is something we wish to remove in the near future, but in the meantime, the following code snippet should help you pack and unpack RGB colors in your PointXYZRGB structure: 这是我们希望在不久的将来删除的内容,但是与此同时,以下代码段应帮助您在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);

To unpack the data into separate values, use: 要将数据解压缩为单独的值,请使用:

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;

Alternatively, from 1.1.0 onwards, you can use pr, pg, and pb directly. 另外,从1.1.0开始,您可以直接使用pr,pg和pb。

Definition at line 559 of file point_types.hpp . 文件point_types.hpp的559行的定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM