Does not name a type problem

asked 2022-04-08 10:10:02 -0500

hichriayoub gravatar image

Hello everyone i am having a problem with a code here i am totally new to c++ and i need help thanks

#include <ros/ros.h>
#include <visualization_msgs/Marker.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <cmath>
#include <ros/ros.h>
#include <sensor_msgs/PointCloud2.h>
#include <pcl_ros/point_cloud.h>
#include <tf/transform_listener.h>
#include <iomanip>
#include <iostream>
#include <pcl/conversions.h>
#include <pcl/ModelCoefficients.h>
#include <pcl/point_types.h>
#include <pcl/common/centroid.h>
#include <pcl/common/common.h>
visualization_msgs::Marker mark_cluster(pcl::PointCloud<pcl::PointXYZ>::Ptr filtere_final, std::string ns ,int id, float r, float g, float b)
{
  Eigen::Vector4f centroid;
  Eigen::Vector4f min;
  Eigen::Vector4f max;



  pcl::compute3DCentroid (*filtere_final, centroid);
  pcl::getMinMax3D (*filtere_final, min, max);

std::cout << "center x " << centroid[0] << std::endl;
std::cout << "center y " << centroid[1] << std::endl;
std::cout << "center z " << centroid[2] << std::endl; 

  uint32_t shape = visualization_msgs::Marker::CUBE;
  visualization_msgs::Marker marker;
  marker.header.frame_id = filtere_final->header.frame_id;
  marker.header.stamp = ros::Time::now();

  marker.ns = ns;
  marker.id = id;
  marker.type = shape;
  marker.action = visualization_msgs::Marker::ADD;

  marker.pose.position.x = centroid[0];
  marker.pose.position.y = centroid[1];
  marker.pose.position.z = centroid[2];
  marker.pose.orientation.x = 0.0;
  marker.pose.orientation.y = 0.0;
  marker.pose.orientation.z = 0.0;
  marker.pose.orientation.w = 1.0;

  marker.scale.x = (max[0]-min[0]);
  marker.scale.y = (max[1]-min[1]);
  marker.scale.z = (max[2]-min[2]);

  if (marker.scale.x ==0)
      marker.scale.x=0.1;

  if (marker.scale.y ==0)
    marker.scale.y=0.1;

  if (marker.scale.z ==0)
    marker.scale.z=0.1;

  marker.color.r = r;
  marker.color.g = g;
  marker.color.b = b;
  marker.color.a = 0.5;

  marker.lifetime = ros::Duration();
//   marker.lifetime = ros::Duration(0.5);

  return marker;

}

ros::Publisher vis_pub;

vis_pub.publish(mark_cluster(output.makeShared(),"marker_name_space", 1, 255, 0, 0));

the problem is

error: ‘vis_pub’ does not name a type 77 | vis_pub.publish(mark_cluster(output.makeShared(),"marker_name_space", 1, 255, 0, 0)); | ^~~~~~~

edit retag flag offensive close merge delete