如何从点云获取颜色信息并显示它? -Qt

问题描述

我有一个彩色的pcd文件,并尝试使用qt对其进行可视化。但是,当打开彩色的pcd文件时,看不到颜色。

PCD File

这是我的代码

pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_rgb (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));


QString fileName_rgba = QFileDialog::getopenFileName(this,tr("Open File"),"/home",tr("Pcd Files (*.pcd)"));

filePath_rgba = fileName_rgba.toStdString();

if (pcl::io::loadPCDFile<pcl::PointXYZRGB> (filePath_rgba,*cloud_rgb) == -1) //* load the file
  {
    PCL_ERROR ("Couldn't read file test_pcd.pcd \n");
    return (-1);
  }

int pointCount = cloud_rgb->width * cloud_rgb->height;
string pointString = "Loaded " + to_string(pointCount) + " data points from " + fileName_rgba.toStdString() + "with the following fields: ";
QString dum = QString::fromStdString(pointString);
ui->pcdInfo->setText(dum);

pviz.removeAllPointClouds();


vtkSmartPointer<vtkRenderWindow> renderWindow = pviz.getRenderWindow();
ui->widget_rgba->SetRenderWindow (renderWindow);

pviz.setupInteractor (ui->widget_rgba->GetInteractor (),ui->widget_rgba->GetRenderWindow ());
pviz.getInteractorStyle ()->setKeyboardModifier (pcl::visualization::INteraCTOR_KB_MOD_SHIFT);

pviz.addPointCloud<pcl::PointXYZRGB>(cloud_rgb);
pviz.setBackgroundColor(0,0.1);


ui->widget_rgba->show();

如何查看此pcd文件彩色版本?

解决方法

这取决于定义pcd文件的内容。假设您有一个带有这样的标题的文件:

# .PCD v0.7 - Point Cloud Data file format
VERSION 0.7
FIELDS x y z rgb
SIZE 4 4 4 4
TYPE F F F F
COUNT 1 1 1 1

然后rgb表示您在点云中确实有颜色

FIELDS x y z rgb

颜色的大小是4个字节

大小4 4 4 4

,并表示为

float TYPE F F F F

因此在数据行中,取最后一个元素

66.873619 -91.371956 773.60254 9.8649324e-039

并从中读取字节R,G,B,例如,浮点9.8649324e-039表示为

00000000 01101011 01101011 01101011
  ^-dc     ^         ^        ^  
           |-Red     |-Green  |
                              |-Blue     

enter image description here


更新:

# .PCD v0.7 - Point Cloud Data file format 
VERSION 0.7 
FIELDS x y z rgba 
label 
SIZE 4 4 4 4 4 
TYPE F F F U U 
COUNT 1 1 1 1 1 
WIDTH 191572 
HEIGHT 1 
VIEWPOINT 0 0 0 1 0 0 0 
POINTS 191572 
DATA binary

在您的情况下,U表示未签名的数据

表示无符号类型uint8(无符号字符),uint16(无符号短型),uint32(无符号int)

所以您的数据

2320 2e50 4344 2076 302e 3720 2d20 506f
|---X---|                     |
_________ |---Y---|           |
                    |---Z---| |
                              |--COLOR--|

所以颜色是“ 2d20 506f

2d 20 50 6f 
 ^-r
   ^-g
      ^b
         ^-a

如此

Red = 0x2D
Green = 0x20
Blue = 0x50
Alpha = 0x6F

将这些值转换为int并创建一个 QColor :)