If I were you, instead of trying to do this directly in RVIZ of Gazebo I would look at how to process the costmap in a custom node, and from there extract the information you want.
Maps in ROS are represented as Occupancy Grids. This stores a discretized (i.e. cells) representation of the environment. From this representation, with the correct logic in a roscpp or rospy node, you can extract the information you want. Here is an example in the ROS nav stack Global Planner Costmap which manipulates this discretized representation in c++. Costmap2D is not exactly a occupancy grid but the concept/representation is similar.
Once you have the grid available to you in c++, I imagine you can produce the logic required to generate the result you want.
What do you mean? Using computational vision or PCL?
I meant from 3d or 2d map. from rviz or gazebo. I want to get all the objects and the space they are occupying(x,y) in the map. for example i might have a map of 10x10, and there is a square in the map positioning [(1,1),(1,3),(3,1),(3,3)] this square is a object.
Hi. If there are objects been showing in the RVIZ than those objects are been published from somewhere. I think you could verify the topic through the RVIZ, and after knowing which type they are, e.g, markers, you will be able to access their position in your code in the proper way.