保存为TUM和KITTI格式的位姿

void SaveKittiFormat(const string& map_path)
{
    FILE *fp = NULL;
    char end1 = 0x0d; // "/n"
    char end2 = 0x0a;

    // lidar odometry
    string lidar_tum_file = map_path + "imu_data_res_kitti.txt";
    fp = fopen(lidar_tum_file.c_str(), "w+");

    if (fp == NULL)
    {
        printf("fail to open file %s ! \n", lidar_tum_file.c_str());
        exit(1);
    }
    else
        printf("KITTI : write lidar data to %s \n", lidar_tum_file.c_str());

    for (int i = 0; i < imu_data_.size(); ++i)
    {
        auto q = imu_data_[i].continous_quat;
        Eigen::Matrix3d R;
        R = q;

        Eigen::Vector3d t = imu_data_[i].pos;
        double time = imu_data_[i].stamp;
        fprintf(fp, "%.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf %.5lf%c",
                R(0,0),R(0,1),R(0,2),t.x(),
                R(1,0),R(1,1),R(1,2),t.y(),
                R(2,0),R(2,1),R(2,2),t.z(),
                end2);
    }
    fclose(fp);
}

void SaveTumFormat(const string& map_path)
{
    FILE *fp = NULL;
    char end1 = 0x0d; // "/n"
    char end2 = 0x0a;

    // lidar odometry
    string lidar_tum_file = map_path + "imu_data_res.txt";
    fp = fopen(lidar_tum_file.c_str(), "w+");

    if (fp == NULL)
    {
        printf("fail to open file %s ! \n", lidar_tum_file.c_str());
        exit(1);
    }
    else
        printf("TUM : write lidar data to %s \n", lidar_tum_file.c_str());

    for (size_t i = 0; i < imu_data_.size(); ++i)
    {
        Eigen::Quaterniond q = imu_data_[i].continous_quat;
        Eigen::Vector3d t = imu_data_[i].pos;
        double time = imu_data_[i].stamp;
        fprintf(fp, "%.3lf %.3lf %.3lf %.3lf %.5lf %.5lf %.5lf %.5lf%c",
                time, t.x(), t.y(), t.z(),
                q.x(), q.y(), q.z(), q.w(), end2);
    }
    fclose(fp);
}

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值