rviz是如何获取图像里选择的点云的3D坐标的

这篇具有很好参考价值的文章主要介绍了rviz是如何获取图像里选择的点云的3D坐标的。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

以前以为rviz是用OpenGL渲染绘图,那么获取图像里像素点对应的真实3D坐标是采用的OpenGL里提供的API实现的,结果一看代码还真不是这样,rviz也就渲染用了OpenGL,其他都是自己实现的,图像界面的实现完全是遵循MVC设计模式自己实现的透视投影和坐标转换等所有相关类。获取点云图像里所选择的点云点的3D坐标相关的代码是这里:

src/rviz/selection/selection_manager.cpp:

bool SelectionManager::getPatchDepthImage(Ogre::Viewport* viewport,
                                          int x,
                                          int y,
                                          unsigned width,
                                          unsigned height,
                                          std::vector<float>& depth_vector)
{
  unsigned int num_pixels = width * height;
  depth_vector.reserve(num_pixels);

  setDepthTextureSize(width, height);


  M_CollisionObjectToSelectionHandler::iterator handler_it = objects_.begin();
  M_CollisionObjectToSelectionHandler::iterator handler_end = objects_.end();

  for (; handler_it != handler_end; ++handler_it)
  {
    handler_it->second->preRenderPass(0);
  }

  if (render(viewport, depth_render_texture_, x, y, x + width, y + height, depth_pixel_box_, "Depth",
             depth_texture_width_, depth_texture_height_))
  {
    uint8_t* data_ptr = (uint8_t*)depth_pixel_box_.data;

    for (uint32_t pixel = 0; pixel < num_pixels; ++pixel)
    {
      uint8_t a = data_ptr[4 * pixel];
      uint8_t b = data_ptr[4 * pixel + 1];
      uint8_t c = data_ptr[4 * pixel + 2];

      int int_depth = (c << 16) | (b << 8) | a;
      float normalized_depth = ((float)int_depth) / (float)0xffffff;
      depth_vector.push_back(normalized_depth * camera_->getFarClipDistance());
    }
  }
  else
  {
    ROS_WARN("Failed to render depth patch\n");
    return false;
  }

  handler_it = objects_.begin();
  handler_end = objects_.end();
  for (; handler_it != handler_end; ++handler_it)
  {
    handler_it->second->postRenderPass(0);
  }

  return true;
}

bool SelectionManager::get3DPatch(Ogre::Viewport* viewport,
                                  int x,
                                  int y,
                                  unsigned width,
                                  unsigned height,
                                  bool skip_missing,
                                  std::vector<Ogre::Vector3>& result_points)
{
  boost::recursive_mutex::scoped_lock lock(global_mutex_);
  ROS_DEBUG("SelectionManager.get3DPatch()");

  std::vector<float> depth_vector;


  if (!getPatchDepthImage(viewport, x, y, width, height, depth_vector))
    return false;


  unsigned int pixel_counter = 0;
  Ogre::Matrix4 projection = camera_->getProjectionMatrix();
  float depth;

  for (unsigned y_iter = 0; y_iter < height; ++y_iter)
    for (unsigned x_iter = 0; x_iter < width; ++x_iter)
    {
      depth = depth_vector[pixel_counter];

      // Deal with missing or invalid points
      if ((depth > camera_->getFarClipDistance()) || (depth == 0))
      {
        ++pixel_counter;
        if (!skip_missing)
        {
          result_points.push_back(Ogre::Vector3(NAN, NAN, NAN));
        }
        continue;
      }


      Ogre::Vector3 result_point;
      // We want to shoot rays through the center of pixels, not the corners,
      // so add .5 pixels to the x and y coordinate to get to the center
      // instead of the top left of the pixel.
      Ogre::Real screenx = float(x_iter + .5) / float(width);
      Ogre::Real screeny = float(y_iter + .5) / float(height);
      if (projection[3][3] == 0.0) // If this is a perspective projection
      {
        // get world-space ray from camera & mouse coord
        Ogre::Ray vp_ray = camera_->getCameraToViewportRay(screenx, screeny);
        // transform ray direction back into camera coords
        Ogre::Vector3 dir_cam = camera_->getDerivedOrientation().Inverse() * vp_ray.getDirection();

        // normalize, so dir_cam.z == -depth
        dir_cam = dir_cam / dir_cam.z * depth * -1;

        // compute 3d point from camera origin and direction*/
        result_point = camera_->getDerivedPosition() + camera_->getDerivedOrientation() * dir_cam;
      }
      else // else this must be an orthographic projection.
      {
        // For orthographic projection, getCameraToViewportRay() does
        // the right thing for us, and the above math does not work.
        Ogre::Ray ray;
        camera_->getCameraToViewportRay(screenx, screeny, &ray);

        result_point = ray.getPoint(depth);
      }

      result_points.push_back(result_point);
      ++pixel_counter;
    }

  return !result_points.empty();
}

bool SelectionManager::get3DPoint(Ogre::Viewport* viewport, int x, int y, Ogre::Vector3& result_point)
{
  ROS_DEBUG("SelectionManager.get3DPoint()");

  std::vector<Ogre::Vector3> result_points_temp;
  bool success = get3DPatch(viewport, x, y, 1, 1, true, result_points_temp);
  if (result_points_temp.empty())
  {
    // return result_point unmodified if get point fails.
    return false;
  }
  result_point = result_points_temp[0];

  return success;
}

世界3D坐标是用的射线法计算出来。SelectionManager::get3DPoint()被rviz里多个地方调用,凡是UI界面上需要查看点的坐标地方都是调用它。文章来源地址https://www.toymoban.com/news/detail-857533.html

到了这里,关于rviz是如何获取图像里选择的点云的3D坐标的的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 基于3D点云的小目标检测学习笔记

    一、与图像相比, 基于点云的目标检测 一直面临着一些 挑战 : 1、 非结构化数据 :点云作为场景中点的位置具有稀疏和非结构化的性质,因此它们的密度和数量都随着场景中对象而变化。 2、 不变性排列 :点云本质上是一长串点(nx3矩阵,其中n是点数)。 在几何上,点

    2024年02月12日
    浏览(28)
  • Open3D快速裁剪指定区域的点云

    Open3D快速裁剪指定区域的点云 Open3D是一个用于计算机视觉和三维重建的开源库,它提供了许多强大的工具来处理点云数据。其中包括一个简单但功能强大的裁剪点云的函数,可以通过指定一个三维框来选择任意指定区域的点。 在本文中,我们将介绍如何在Open3D中使用该函数

    2024年02月07日
    浏览(31)
  • 3D点云分割系列5:RandLA-Net:3D点云的实时语义分割,随机降采样的重生

    《RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds》发布于CVPR 2020。 在自动驾驶等领域,高效的分割网络是目前最基本和最关键的研究方向。目前存在的一些点云处理方法包括PointNet、PointNet++、PointCNN、KPConv等方法,或多或少都存在效率不高或是特征采样不足的情况,

    2024年02月04日
    浏览(37)
  • 基于Open3D的点云处理16-特征点匹配

    将点云数据统一到一个世界坐标系的过程称之为点云配准或者点云拼接。(registration/align) 点云配准的过程其实就是找到同名点对;即找到在点云中处在真实世界同一位置的点。 常见的点云配准算法: ICP、Color ICP、Trimed-ICP 算法流程: 选点: 确定参与到配准过程中的点集。 匹

    2024年02月10日
    浏览(46)
  • [论文阅读]PillarNeXt——基于LiDAR点云的3D目标检测网络设计

    PillarNeXt: Rethinking Network Designs for 3D Object Detection in LiDAR Point Clouds 基于LiDAR点云的3D目标检测网络设计 论文网址:PillarNeXt 代码:PillarNeXt 这篇论文\\\"PillarNeXt: Rethinking Network Designs for 3D Object Detection in LiDAR Point Clouds\\\"重新思考了用于激光雷达点云3D目标检测的网络设计。主要的贡献

    2024年02月08日
    浏览(31)
  • 使用python-open3d读取pcd,bin格式的点云,并显示

    open3d读取pcd格式点云 效果图    用open3d读取bin文件   效果图     

    2024年02月11日
    浏览(40)
  • 基于Open3D的点云处理17-Open3d的C++版本

    http://www.open3d.org/docs/latest/cpp_api.html http://www.open3d.org/docs/latest/getting_started.html#c http://www.open3d.org/docs/release/cpp_project.html#cplusplus-example-project https://github.com/isl-org/open3d-cmake-find-package https://github.com/isl-org/open3d-cmake-external-project https://github.com/isl-org/Open3D/releases Note: -DBUILD_SHARED_LIBS

    2024年02月09日
    浏览(47)
  • Open3D 计算点云的倒角距离(Chamfer Distance)

      Chamfer Distance距离可以计算生成点云数据与标签点云数据之间的平均最短点距离。Open3D可以直接用来计算点云的Chamfer Distance距离,关于的Chamfer Distance距离在点云上应用的更多详细介绍可以参考:PCL 计算点云的倒角距离(Chamfer Distance)或硕士论文: [1]张永涵. 基于深度学

    2024年02月12日
    浏览(32)
  • 【3D目标检测】基于伪雷达点云的单目3D目标检测方法研宄

    本文是基于单目图像的3D目标检测方法,是西安电子科技大学的郭鑫宇学长的硕士学位论文。 【2021】【单目图像的3D目标检测方法研究】 研究的问题: 如何提高伪点云的质量 伪点云体系中如何提高基于点云的检测算法的效果 提出的方法: 一种基于置信度的伪点云采样方法

    2024年02月06日
    浏览(40)
  • Open3D 格网法计算点云的占地面积

      该方法主要用于粗略统计机载点云的占地面积。方法原理是将点云沿 X O Y XOY X O Y 面划分成格网,统计有点的格网面积来近似表示点云占地面积。

    2024年02月05日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包