【问题标题】:How to obtain color information from a point cloud and display it? -Qt如何从点云中获取颜色信息并显示出来? -Qt
【发布时间】:2020-09-15 18:22:34
【问题描述】:

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

这是我的代码:

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, 0.1);


ui->widget_rgba->show();

我怎样才能看到这个 pcd 文件的彩色版本?

【问题讨论】:

  • 请分享一行到pcd文件的一个点!
  • 2320 2e50 4344 2076 302e 3720 2d20 506f 这是我的 pcd 文件中的一行。 @ΦXocę웃Пepeúpaツ
  • 什么是 pviz???

标签: c++ qt point-cloud-library


【解决方案1】:

这取决于定义 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 表示你在点云中确实有颜色,

字段 x y z rgb

颜色大小为4字节

尺寸 4 4 4 4

并表示为一个

浮点型 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     


更新:

# .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(unsigned char)、uint16(unsigned short)、uint32(unsigned 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 :)

【讨论】:

  • 我没有这样的标题。
  • 你的文件有什么标题??
  • 哦,好的,找到标题。我的标题看起来像这样,但是当我尝试将其可视化时,我看不到颜色。
  • # .PCD v0.7 - 点云数据文件格式版本 0.7 FIELDS x y z rgba label SIZE 4 4 4 4 4 TYPE F F F U COUNT 1 1 1 1 1 WIDTH 191572 HEIGHT 1 VIEWPOINT 0 0 0 1 0 0 0 点 191572 数据二进制
  • 是的,你看不到颜色,因为你忽略/错过了数据
猜你喜欢
  • 1970-01-01
  • 2014-05-12
  • 1970-01-01
  • 2011-05-09
  • 1970-01-01
  • 2018-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多