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;
    }
}
相关推荐
3DVisionary16 分钟前
升维洞察:DIC全场视觉检测如何重塑力学测试的“时空秩序”
人工智能·计算机视觉·视觉检测·动态测量·dic技术·xtdic·结构疲劳演化
m0_7431064629 分钟前
【浙大&南洋理工最新综述】Feed-Forward 3D Scene Modeling(一)
论文阅读·人工智能·计算机视觉·3d·几何学
爱思考的观赏鱼1 小时前
YOLO 系列:2026最新遥感检测:YOLOv11-OBB 旋转框训练、参数调优与踩坑全解析
人工智能·yolo·目标检测·机器学习·计算机视觉·目标跟踪
格林威1 小时前
工业视觉检测:OpenCV FPS 正确计算的方式
运维·人工智能·数码相机·opencv·机器学习·计算机视觉·视觉检测
youcans_2 小时前
【HALCON 实战入门】2. HALCON 快速入门
图像处理·人工智能·计算机视觉·halcon
房开民2 小时前
OpenCV 中 cv::split() 的最基础用法
人工智能·opencv·计算机视觉
昵称小白2 小时前
目标检测到底在做什么:分类、检测、分割的区别(三)
人工智能·计算机视觉·目标跟踪
AI即插即用3 小时前
即插即用系列 | SCTNet: 协同CNN与Transformer,池化注意力融合的高光谱图像分类网络
人工智能·深度学习·计算机视觉·分类·cnn·transformer
三毛的二哥3 小时前
障碍物遮挡判断算法
人工智能·算法·计算机视觉·3d
羊羊小栈3 小时前
基于「YOLO目标检测 + 多模态AI分析」的增材制造粉末床熔合缺陷智能检测分析预警系统
人工智能·yolo·目标检测·计算机视觉·毕业设计·制造