首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >测量Yolo检测到的物体的尺寸。例如。高度、宽度、与摄像机的距离

测量Yolo检测到的物体的尺寸。例如。高度、宽度、与摄像机的距离
EN

Stack Overflow用户
提问于 2019-05-22 20:14:33
回答 1查看 451关注 0票数 0

我使用的是ubuntu 16.04和ROS kinetic。对于我的项目工作,我已经用YOLO暗网检测到了门和门把手。为此,我使用了英特尔realsense d435摄像头。

现在我的问题如下:

我怎样才能测量门和摄像机之间的距离?

我怎样才能测量门的高度和宽度?

如何在rviz 3d中添加检测到的门。

EN

回答 1

Stack Overflow用户

发布于 2019-05-24 04:47:02

(1)如何测量门与摄像头之间的距离?

PCL样本普查见pcl样本。它会给你实际的垂直距离,应该是d。,ax+by+cz+d=0。

(2)如何测量门的高度和宽度?

采样共识结果以获得内联,然后使用PCA或任何必要的手段确定原则方向。基础做主导方向,沿主导方向测量最大和最小。那应该能让你长高。对宽度执行相同的操作

(3)如何在rviz 3d中添加检测到的门。相同的检测和发布

下面是一个简短的示例,或者你是如何做的

代码语言:javascript
复制
ros::Publisher pub;

float deg2rad(float alpha)
{
  return (alpha * 0.017453293f);
}

void ransac(pcl::PointCloud<pcl::PointXYZRGB>::Ptr input, pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_projected)
{
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
  *cloud = *input;

  pcl::ModelCoefficients::Ptr floor_coefficients(new pcl::ModelCoefficients());
  pcl::PointIndices::Ptr floor_indices(new pcl::PointIndices());
  pcl::SACSegmentation<pcl::PointXYZRGB> floor_finder;
  floor_finder.setOptimizeCoefficients(true);
  floor_finder.setModelType(pcl::SACMODEL_PARALLEL_PLANE);
  // floor_finder.setModelType (SACMODEL_PLANE);
  floor_finder.setMethodType(pcl::SAC_RANSAC);
  floor_finder.setMaxIterations(300);
  floor_finder.setAxis(Eigen::Vector3f(0, 0, 1));
  floor_finder.setDistanceThreshold(0.08);
  floor_finder.setEpsAngle(deg2rad(5));
  floor_finder.setInputCloud(boost::make_shared<pcl::PointCloud<pcl::PointXYZRGB> >(*cloud));
  floor_finder.segment(*floor_indices, *floor_coefficients);

  if (floor_indices->indices.size() > 0)
  {
    // Extract the floor plane inliers
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr floor_points(new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::ExtractIndices<pcl::PointXYZRGB> extractor;
    extractor.setInputCloud(boost::make_shared<pcl::PointCloud<pcl::PointXYZRGB> >(*cloud));
    extractor.setIndices(floor_indices);
    extractor.filter(*floor_points);
    extractor.setNegative(true);
    extractor.filter(*cloud);

    // Project the floor inliers
    pcl::ProjectInliers<pcl::PointXYZRGB> proj;
    proj.setModelType(pcl::SACMODEL_PLANE);
    proj.setInputCloud(floor_points);
    proj.setModelCoefficients(floor_coefficients);
    proj.filter(*cloud_projected);

    floor_points->header.frame_id = "camera_link";
    floor_points->header.stamp = ros::Time::now().toNSec();
   }
}

void passthrough_z(const sensor_msgs::PointCloud2ConstPtr& input, pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_passthrough)
{
    pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
    pcl::fromROSMsg(*input, *cloud);

    // Create the filtering object
    pcl::PassThrough<pcl::PointXYZRGB> pass;
    pass.setInputCloud (boost::make_shared<pcl::PointCloud<pcl::PointXYZRGB> >(*cloud));
    pass.setFilterFieldName ("z");
    pass.setFilterLimits (0.0, 6.0);
    pass.filter (*cloud_passthrough);
}

void passthrough_y(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_passthrough)
{
    // Create the filtering object
    pcl::PassThrough<pcl::PointXYZRGB> pass;
    pass.setInputCloud (boost::make_shared<pcl::PointCloud<pcl::PointXYZRGB> >(*cloud_passthrough));
    pass.setFilterFieldName ("y");
    pass.setFilterLimits (0.0, 5.0);
    pass.filter (*cloud_passthrough);
}

void passthrough_x(pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_passthrough)
{
    // Create the filtering object
    pcl::PassThrough<pcl::PointXYZRGB> pass;
    pass.setInputCloud (boost::make_shared<pcl::PointCloud<pcl::PointXYZRGB> >(*cloud_passthrough));
    pass.setFilterFieldName ("x");
    pass.setFilterLimits (-2.0, 2.0);
    pass.filter (*cloud_passthrough);
}

void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& input)
{
  // Do data processing here...

  // run pass through filter to shrink point cloud
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_passthrough(new pcl::PointCloud<pcl::PointXYZRGB>);
  passthrough_z(input, cloud_passthrough);
  passthrough_y(cloud_passthrough);
  passthrough_x(cloud_passthrough);

  // run ransac to find floor
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZRGB>);
  ransac(cloud_passthrough, cloud_projected);
  pub.publish(*cloud_projected);
}

int main (int argc, char** argv)
{
  // Initialize ROS
  ros::init (argc, argv, "pcl_node");
  ros::NodeHandle nh;

  // Create a ROS subscriber for the input point cloud
  ros::Subscriber sub = nh.subscribe ("camera/depth_registered/points", 1, cloud_cb);

  // Create a ROS publisher for the output point cloud
  pub = nh.advertise<sensor_msgs::PointCloud2> ("output", 1);

  // Spin
  ros::spin ();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56256575

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档