【深度学习|抓取检测|数据集】Cornell 康奈尔数据集下载及解析 & txt 转 pcd格式 & 点云可视化

本文介绍了如何使用PCL库将康奈尔数据集中txt格式的点云数据转换为PCD文件,并展示了如何利用pcl_viewer进行可视化。通过代码实例,读者将学会读取txt文件、解析数据并保存为PCD,以便后续处理和三维展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现效果

在这里插入图片描述

数据集来源

链接: https://pan.baidu.com/s/1IccviO-UJCoArctGVEdBkA 提取码: s0p0

基础知识

首先要了解 PCL 官方教程给出的关于 PCD 文件的格式。

PCD(点云数据)文件格式🔗

下面是康奈尔数据集中 pcd0100.txt 的内容:

# .PCD v.7 - Point Cloud Data file format # 指定PCD文件版本
# FIELDS 指定点可以拥有的每个维度/字段的名称
FIELDS x y z rgb index
# SIZE 指定每个维度的大小(以字节为单位),其中,无符号int/int/float有4字节
SIZE 4 4 4 4 4
# TYPE 以字符的形式指定每个维度的类型
# U-表示无符号类型uint8(无符号字符),uint16(无符号短),uint32(无符号int)
# F-表示浮点类型
TYPE F F F F U
# COUNT 指定每个维度有多少个元素
COUNT 1 1 1 1 1
# WIDTH 指定点云数据集的宽度,在这里指定无组织数据集的云中点总数,因为 HEIGHT = 1
WIDTH 253674
# HEIGHT 指定点云数据集的高度,以点数为大小。这里是无组织数据集,所以设置为 1
HEIGHT 1
# VIEWPOINT 为数据集中的点指定获取视图,视图信息指定为平移(tx ty tz)+四元数(qw qx qy qz)
VIEWPOINT 0 0 0 1 0 0 0
# POINTS 指定云中的点总数
POINTS 253674
# DATA 指定存储点云数据的数据类型
DATA ascii
1924.064 -647.111 -119.4176 0 25547
1924.412 -649.678 -119.7147 0 25548
1919.929 -650.5591 -116.9839 0 25549
1920.276 -653.1166 -117.2799 0 25550
1920.622 -655.6741 -117.576 0 25551

可视化

利用 pcl_viewer这个可执行文件可以直接可视化 pcd 文件,但遗憾的是我们的康奈尔数据集给出的是 txt 格式。

文件格式转换(txt 转 pcd)

  • 自己参考官方教程和一些博客,然后写的代码,可以通过编译并运行。
  • 代码实现的功能:读取康奈尔数据集中的txt文件,写入pcd文件并可视化。

代码中参考了如下链接:
[1] PCL可视化工具
[2] 【PCL学习】将pcd格式点云与txt格式文本互转

//
// Created by zth on 2021/8/10.
//

#include <iostream>
#include <string>
#include <vector>
#include <thread>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>


//定位到txt文件的某一行(注意:从第0行算起)
std::ifstream & seek_to_line(std::ifstream & in, int line_num)
//将打开的文件in,定位到line行。
{
    std::string info_line;
    in.seekg(0, std::ios::beg);  //定位到文件开始。
    std::cout << "文件信息:" << std::endl;
    for (int i = 0; i < line_num; i++)
    {
        getline(in,info_line);
        std::cout << info_line << std::endl;
    }
    return in;
}

// 按空格分割 string
std::vector<std::string> split(const std::string& str, const std::string& delim) {
    std::vector<std::string> res;
    if("" == str) return res;
    //先将要切割的字符串从string类型转换为char*类型
    char * strs = new char[str.length() + 1] ; //不要忘了
    strcpy(strs, str.c_str());

    char * d = new char[delim.length() + 1];
    strcpy(d, delim.c_str());

    char *p = strtok(strs, d);
    while(p) {
        std::string s = p; //分割得到的字符串转换为string类型
        res.push_back(s); //存入结果数组
        p = strtok(NULL, d);
    }

    return res;
}

// 可视化点云
pcl::visualization::PCLVisualizer::Ptr rgbVis (pcl::PointCloud<pcl::PointXYZRGB>::ConstPtr cloud)
{
    // --------------------------------------------
    // -----Open 3D viewer and add point cloud-----
    // --------------------------------------------
    pcl::visualization::PCLVisualizer::Ptr viewer (new pcl::visualization::PCLVisualizer ("3D Viewer"));
    viewer->setBackgroundColor (0, 0, 0);
    pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(cloud);
    viewer->addPointCloud<pcl::PointXYZRGB> (cloud, rgb, "sample cloud");
    viewer->addCoordinateSystem (100.0); // 添加坐标系
    return (viewer);
}

int main() {

    // 定义点云数据结构体
    typedef struct tagPOINT_3D{
        float x;
        float y;
        float z;
        float rgb;
        int index;
    }POINT_WORLD;

    // 读取 txt 文件
    tagPOINT_3D point_3d;
    std::ifstream infile("../data-1/pcd0148.txt");
    std::string filename;
    std::string line;
    std::vector<tagPOINT_3D> point_vec; // 存储点云文件的数据行
    if(infile) // 有该文件
    {
        seek_to_line(infile, 10);
        while (getline (infile, line)) // line中不包括每行的换行符
        {
            // 将 string 转化为 float 和 int 型并赋给结构体
            point_3d.x = stod(split(line, " ")[0]);
            point_3d.y = stod(split(line, " ")[1]);
            point_3d.z = stod(split(line, " ")[2]);
            point_3d.rgb = stod(split(line, " ")[3]);
            point_3d.index = stoi(split(line, " ")[4]);
            point_vec.push_back(point_3d);
        }
        std::cout << "开始打印" << std::endl;
        for(int i=0;i<3;i++){
            std::cout << point_vec[i].x << point_vec[i].y << point_vec[i].z << point_vec[i].rgb << std::endl;
        }
    }
    else // 没有该文件
    {
        std::cout <<"no such file" << std::endl;
    }

    // 写入点云文件
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
    point_cloud_ptr->width = point_vec.size();
    point_cloud_ptr->height = 1;
    point_cloud_ptr->is_dense = false;
    point_cloud_ptr->resize(point_cloud_ptr->width * point_cloud_ptr->height);

    for(int i = 0; i < point_vec.size(); i++){
        point_cloud_ptr->points[i].x = point_vec[i].x;
        point_cloud_ptr->points[i].y = point_vec[i].y;
        point_cloud_ptr->points[i].z = point_vec[i].z;
        point_cloud_ptr->points[i].rgb = point_vec[i].rgb;
    }

    pcl::io::savePCDFileASCII ("test_pcd.pcd", *point_cloud_ptr);
    std::cerr << "Saved " << point_cloud_ptr->size () << " data points to test_pcd.pcd." << std::endl;

    // 可视化点云
    pcl::visualization::PCLVisualizer::Ptr viewer;
    viewer = rgbVis(point_cloud_ptr);

    // 窗口刷新
    // 方法 1:
//    while (!viewer->wasStopped ())
//    {
//        viewer->spinOnce (100);
//        std::this_thread::sleep_for(std::chrono::milliseconds(100));//睡眠100毫秒
//    }

    // 方法 2:
    viewer->spin();

    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(txt2pcd)
set(CMAKE_CXX_STANDARD 14)

set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "/opt/homebrew/Cellar/qt@5/5.15.2/lib/cmake/Qt5")

#find_package(PCL 1.12 REQUIRED COMPONENTS common io)
find_package(PCL 1.12 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS}) # 包含头文件目录
link_directories(${PCL_LIBRARY_DIRS}) # 设置依赖库链接目录
add_definitions(${PCL_DEFINITIONS}) # 添加预处理器和编译器标记

add_executable(txt2pcd main2.cpp)
target_link_libraries(txt2pcd ${PCL_LIBRARIES})
&lt;think&gt;好的,用户需要关于Cornell数据集在目标检测方面的资料、教程、使用方法以及下载信息。首先,我需要确认Cornell数据集的具体情况。根据用户提供的引用[1],Cornell大学有一个名为Ithaca365的数据集,主要用于恶劣天气下的3D目标检测。这个数据集收集了在15公里路线上重复40次采集的图像和点云数据,并提供了3D边界框标注等信息。因此,用户提到的Cornell数据集很可能是指Ithaca365。 接下来,我需要整理该数据集下载地址和使用方法。根据引用[1],数据集的地址是https://ithaca365.mae.cornell.edu/,这里应该可以找到下载链接和文档。此外,用户可能需要了解如何加载数据集、处理数据格式以及应用目标检测模型。例如,数据可能以KITTI或Argoverse的格式存储,用户可以参考已有的Point R-CNN模型进行迁移学习。 关于教程,用户可能需要指导如何处理点云数据、使用3D目标检测框架,或者如何在该数据集上训练和验证模型。此外,引用[2]提到具身人工智能的数据集整理,但这里可能相关性不大,不过可以提醒用户更多相关数据集资源。 用户可能遇到的问题包括数据格式换、标注的使用、环境配置等,需要建议查阅官方文档和相关论文。同时,引用[3]中的方法可能适用于网页元素检查,但在这里不太相关,不过可以忽略。 最后,生成相关问题需要考虑用户可能的后续需求,比如数据预处理、模型选择、性能评估等。确保回答结构清晰,步骤明确,并正确引用提供的资料。&lt;/think&gt;### Cornell数据集在目标检测中的使用指南 #### 1. 数据集简介 Cornell大学发布的**Ithaca365**数据集专注于恶劣天气下的3D目标检测任务[^1],包含数十万帧图像与对齐的点云数据,其中7,000帧提供了精细标注: - **amodel road segmentation labels**(道路分割标签) - **amodel instance segmentation labels**(实例分割标签) - **3D bounding box labels**(3D边界框标签) #### 2. 数据集下载 - **官方地址**: https://ithaca365.mae.cornell.edu/ - **数据内容**: 包含传感器数据(LiDAR、摄像头)、标注文件、采集路径元数据 - **论文参考**: 技术细节可查阅论文 https://arxiv.org/pdf/2208.01166.pdf #### 3. 使用流程 **步骤1:数据预处理** - 使用官方提供的`calibration files`对齐多传感器数据 - 将点云数据换为KITTI格式(常用兼容格式): ```python import numpy as np point_cloud = np.fromfile(&#39;lidar.bin&#39;, dtype=np.float32).reshape(-1,4) ``` **步骤2:模型训练** - 推荐使用Point R-CNN等3D检测框架 - 迁移学习示例(PyTorch): ```python from models.pointrcnn import PointRCNN model = PointRCNN(num_classes=3).cuda() # 加载预训练权重(如KITTI预训练模型) model.load_state_dict(torch.load(&#39;pretrained.pth&#39;)) ``` **步骤3:评估验证** - 使用官方评估脚本计算mAP(平均精度) - 注意天气标签的交叉验证(雨/雪/雾等不同条件) #### 4. 关键技巧 - **多模态融合**: 结合RGB图像与LiDAR点云提升雨雾天气下的检测鲁棒性 - **数据增强**: 添加人工雨雪噪声模拟极端天气 - **标注解析**: 使用`amodel_tools`工具包处理实例分割标签
评论 22
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宇宙爆肝锦标赛冠军

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值