lot*_*ine 0 c++ rgb point-cloud-library
我有一个点云。我想得到它的RGB值。我怎样才能做到这一点?
\n 为了让我的问题更清楚,请查看代码。
// Load the first input file into a PointCloud<T> with an appropriate type : \n pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud1 (new pcl::PointCloud<pcl::PointXYZRGB>);\n if (pcl::io::loadPCDFile<pcl::PointXYZRGB> ("../data/station1.pcd", *cloud1) == -1)\n {\n std::cout << "Error reading PCD file !!!" << std::endl;\n exit(-1);\n }\nRun Code Online (Sandbox Code Playgroud)\n\n我想单独获取每个值
\n\nstd::cout << " x = " << cloud1->points[11].x << std::endl;\nstd::cout << " y = " << cloud1->points[11].y << std::endl;\nstd::cout << " z = " << cloud1->points[11].z << std::endl;\nstd::cout << " r = " << cloud1->points[11].r << std::endl;\nstd::cout << " g = " << cloud1->points[11].g << std::endl;\nstd::cout << " b = " << cloud1->points[11].b << std::endl;\nRun Code Online (Sandbox Code Playgroud)\n\n但结果我得到了类似的东西:
\n\n x = 2.33672\n y = 3.8102\n z = 8.86153\n r = \xef\xbf\xbd\n g = w\n b = \xef\xbf\xbd\nRun Code Online (Sandbox Code Playgroud)\n
表示欧几里德 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);
Run Code Online (Sandbox Code Playgroud)
要将数据解压缩为单独的值,请使用:
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;
Run Code Online (Sandbox Code Playgroud)
或者,从 1.1.0 开始,您可以直接使用 pr、pg 和 pb。
文件point_types.hpp第559行的定义。
| 归档时间: |
|
| 查看次数: |
4983 次 |
| 最近记录: |