Airsim仿真双目相机时间戳不同步的解决办法

settings.json

bash 复制代码
{
  "SeeDocsAt": "https://github.com/Microsoft/AirSim/blob/main/docs/settings.md",
  "SettingsVersion": 1.2,
  "SimMode": "Multirotor",
  "ViewMode": "NoDisplay",
  "ClockSpeed": 1.0,
  "LocalHostIp": "192.168.35.220",
  "ApiServerPort": 41451,
  "Vehicles": {
    "drone_1": {
      "VehicleType": "SimpleFlight",
      "DefaultVehicleState": "Armed",
      "EnableCollisionPassthrogh": false,
      "EnableCollisions": true,
      "AllowAPIAlways": true,
      "Cameras": {
        "front_left_custom": {
          "CaptureSettings": [
            {
              "PublishToRos": 1,
              "ImageType": 0,
              "Width": 672,
              "Height": 376,
              "FOV_Degrees": 120,
              "TargetGamma": 1.5
            }
          ],
          "X": 0.50, "Y": -0.06, "Z": 0.10,
          "Pitch": 0.0, "Roll": 0.0, "Yaw": 0.0
        },
        "front_right_custom": {
          "CaptureSettings": [
            {
              "PublishToRos": 1,
              "ImageType": 0,
              "Width": 672,
              "Height": 376,
              "FOV_Degrees": 120,
              "TargetGamma": 1.5
            }
          ],
          "X": 0.50, "Y": 0.16, "Z": 0.10,
          "Pitch": 0.0, "Roll": 0.0, "Yaw": 0.0
        }
      },
      "X": 0,
      "Y": 0,
      "Z": 0,
      "Pitch": 0,
      "Roll": 0,
      "Yaw": 0
    }
  }
}

airsim_ros_pkgs/src/airsim_ros_wrapper.cpp

cpp 复制代码
void AirsimROSWrapper::img_response_timer_cb(const ros::TimerEvent& event)
{
    try {
        int image_response_idx = 0;

        uint64_t kk;

        for (const auto& airsim_img_request_vehicle_name_pair : airsim_img_request_vehicle_name_pair_vec_) {
            const std::vector<ImageResponse>& img_response = airsim_client_images_.simGetImages(airsim_img_request_vehicle_name_pair.first, airsim_img_request_vehicle_name_pair.second);
            
            // 创建 img_response 的副本,修改副本的时间戳
            std::vector<ImageResponse> img_response_copy = img_response;

            if (image_response_idx == 0){
                kk = img_response_copy[0].time_stamp;  // 获取第一个元素的时间戳
            }
            else {
                img_response_copy[0].time_stamp = kk;  // 使用保存的时间戳
            }

            if (img_response_copy.size() == airsim_img_request_vehicle_name_pair.first.size()) {
                process_and_publish_img_response(img_response_copy, image_response_idx, airsim_img_request_vehicle_name_pair.second);
                image_response_idx += img_response_copy.size();
            }

            // if (img_response.size() == airsim_img_request_vehicle_name_pair.first.size()) {
            //     process_and_publish_img_response(img_response, image_response_idx, airsim_img_request_vehicle_name_pair.second);
            //     image_response_idx += img_response.size();
            // }
        }
    }

    catch (rpc::rpc_error& e) {
        std::string msg = e.get_error().as<std::string>();
        std::cout << "Exception raised by the API, didn't get image response." << std::endl
                  << msg << std::endl;
    }
}
相关推荐
AI人工智能+23 分钟前
智能文档抽取系统通过“视觉感知+大模型认知“双引擎架构,实现非结构化文档的自动化处理
深度学习·计算机视觉·语言模型·自然语言处理·ocr·文档抽取
牧羊人.33313 小时前
计算机视觉基础|第2章 OpenCV图像基础操作(读写、窗口、像素操作)
人工智能·opencv·计算机视觉
双翌视觉18 小时前
可见光之外的视界,短波红外成像技术能做什么?
人工智能·计算机视觉·视觉检测
春末的南方城市1 天前
消费级显卡迎来实时视频生成!FastVideo 开源 FastWan-QAD,RTX 5090 实现 1.8 秒生成 5 秒 480P 视频!
人工智能·深度学习·计算机视觉·aigc·音视频
满怀冰雪2 天前
19-图像数据处理:PaddleVision Transform 实战
人工智能·深度学习·计算机视觉·paddle
123_不打狼2 天前
零基础到就业:完整计算机视觉系统化学习路线指南
人工智能·学习·计算机视觉
Clipp_Huang2 天前
光学跟踪系统标定
人工智能·计算机视觉·重构·机器视觉
weixin_468466852 天前
目标检测精度上限与影响因素分析
图像处理·人工智能·目标检测·计算机视觉·图像分类·coco·检测精度
sali-tec2 天前
C# 基于OpenCv的视觉工作流-章102-车牌识别
图像处理·人工智能·opencv·计算机视觉
陈嘿萌3 天前
ECCV 2026 | 南开&OPPO开源 ExpoMotion:首个大规模动态多曝光融合数据集
人工智能·计算机视觉·图像融合·南开大学·新数据集·expomotion·多曝光融合