C++提取目标识别矩阵三维空间坐标源码

废话不多说,直接上代码

#include <iostream>
#include <fstream>
#include <vector>
#include <string>

int main() {
    std::fstream file;
    file.open("C:/Users/537/Desktop/test.txt", std::ios::in);  // Replace "/path/to/file.txt" with the actual file path

    if (!file.is_open()) {
        std::cout << "File open failed." << std::endl;
        return 0;
    }

    std::vector<std::string> data;
    std::string line;

    while (std::getline(file, line)) {
        data.push_back(line);
    }

    file.close();

    std::vector<std::vector<float>> positions;

    for (const auto& item : data) {
        std::string str = item;
        std::string delimiter = ",";
        size_t pos = 0;
        std::vector<float> position;

        while ((pos = str.find(delimiter)) != std::string::npos) {
            std::string token = str.substr(1, pos - 1);
            str.erase(0, pos + delimiter.length());

            position.push_back(std::stof(token));
        }

        // Extract the last value
        std::string lastToken = str.substr(0, str.length() - 1);
        position.push_back(std::stof(lastToken));

        positions.push_back(position);
    }

    // Print the positions
    for (const auto& position : positions) {
        for (const auto& coordinate : position) {
            std::cout << coordinate << " ";
        }
        std::cout << std::endl;
    }

   
    // Output the specified array's spatial position
    int arrayIndex;
    std::cout << "Enter the array index to output the spatial position: ";
    std::cin >> arrayIndex;
    std::cout << positions[0][1];
    std::cout << positions[1][1];
    std::cout << positions[2][1];


    return 0;
}

代码比较简单,只需把上述保存识别目标三维空间的.txt文件地址换成你的,或者你需要一些其他功能,可以稍作修改即可

加油!奥里给

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

跟着小霖学技术

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

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

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

打赏作者

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

抵扣说明:

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

余额充值