std::map<KeyFrame *, std::tuple<int, int>> mObservations; mObservations如何打印?

如果你有一个std::map,其键是指向KeyFrame对象的指针,而值是一个std::tuple包含两个整数(假设这代表了某种观测的数据),你可以通过遍历这个std::map来打印出所有键值对。下面是一个简单的示例,展示如何做到这一点:

#include <iostream>
#include <map>
#include <tuple>

// 假设KeyFrame结构体或类已定义
struct KeyFrame {
    // KeyFrame的成员
    int id; // 仅作为示例
    KeyFrame(int i) : id(i) {} // 简单的构造函数
};

// 假设mObservations已定义并填充了数据
std::map<KeyFrame*, std::tuple<int, int>> mObservations;

// 打印函数
void printObservations() {
    for (const auto& item : mObservations) {
        KeyFrame* keyFrame = item.first;
        std::tuple<int, int> observation = item.second;

        // 获取tuple中的数据
        int obs1 = std::get<0>(observation);
        int obs2 = std::get<1>(observation);

        // 打印KeyFrame的信息(这里打印它的id)和观测的数据
        std::cout << "KeyFrame ID: " << keyFrame->id << ", Observation: (" << obs1 << ", " << obs2 << ")" << std::endl;
    }
}

// 主函数,仅作为示例使用
int main() {
    // 填充mObservations的示例数据
    KeyFrame* kf1 = new KeyFrame(1);
    KeyFrame* kf2 = new KeyFrame(2);

    mObservations[kf1] = std::make_tuple(10, 20);
    mObservations[kf2] = std::make_tuple(30, 40);

    // 打印所有观测
    printObservations();

    // 清理分配的内存
    delete kf1;
    delete kf2;

    return 0;
}

这个代码定义了一个KeyFrame结构体,它有一个名为id的成员变量。mObservations是一个std::map,它将KeyFrame指针映射到一个包含两个整数的std::tuple。printObservations函数遍历mObservations,并为每个键值对打印KeyFrame的id和观测值。

请根据你的实际情况调整KeyFrame结构体或类的定义以及printObservations函数中的打印逻辑。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
用python帮我把下面标签中的有效数据提取出来<annotation> <folder>converted/CMS/2D目标检测/filter</folder> <filename>converted/CMS/2D目标检测/filter_empty_target_img_after_hash2/0/20230401180910649_61.jpg</filename> <source> <database>Unknown</database> <annotation>Unknown</annotation> <image>Unknown</image> </source> <size> <width>1920</width> <height>1536</height> <depth></depth> </size> <segmented>0</segmented> <object> <name>二轮车</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>626.38</xmin> <ymin>808.12</ymin> <xmax>650.03</xmax> <ymax>852.04</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>6</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1612.74</xmin> <ymin>831.51</ymin> <xmax>1627.34</xmax> <ymax>873.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>8</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> <object> <name>行人</name> <truncated>0</truncated> <occluded>0</occluded> <difficult>0</difficult> <bndbox> <xmin>1469.0</xmin> <ymin>832.96</ymin> <xmax>1489.43</xmax> <ymax>865.8</ymax> </bndbox> <attributes> <attribute> <name>rotation</name> <value>0.0</value> </attribute> <attribute> <name>track_id</name> <value>9</value> </attribute> <attribute> <name>keyframe</name> <value>True</value> </attribute> </attributes> </object> </annotation>
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

草莓奶忻

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

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

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

打赏作者

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

抵扣说明:

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

余额充值