You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C++读取配置文件float至Eigen::Vector4f后PCL异常的排查与解决

问题描述

我有一个配置文件,内容包含crop_min_x = -5.0f。尝试通过以下C++代码读取该配置:

std::ifstream config_file_path("config.txt");
std::string line;
while (std::getline(config_file_path, line)) {
    std::istringstream sin(line.substr(line.find("=") + 1));
    if (line.find("num") != -1)
        sin >> config.num;
    else if (line.find("crop_min_x") != -1)
        sin >> config.crop_min_x;
}

对应的Config结构体定义如下:

struct Config {
    int    num;
    float crop_min_x;
};
Config config;

将读取到的值用于PCL点云裁剪:

Eigen::Vector4f min_pt (config.crop_min_x, -5.0f, -5.0f, 1.0f);

程序运行时KDTree环节报错:

[pcl::KdTreeFLANN::setInputCloud] Cannot create a KDTree with an empty input cloud!

但直接写死参数为Eigen::Vector4f min_pt (-5.0f, -5.0f, -10.0f, 1.0);时,程序运行正常。需要实现通过配置文件灵活配置参数的功能。

解决方法

经排查,问题根源是遗漏读取crop_max_x、crop_max_y、crop_max_z参数。在配置文件中补充这些参数,并在代码中添加对应的读取逻辑后,程序已正常运行。


内容的提问来源于stack exchange,提问作者you_know_who

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 08:20:26