FeatureExtractorROSE.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 import rospy
3 import numpy as np
4 from rose2.msg import ROSEFeatures
5 from nav_msgs.msg import OccupancyGrid
6 from visualization_msgs.msg import MarkerArray
7 from skimage.util import img_as_ubyte
8 from util import MsgUtils as mu
9 from PIL import Image as ImagePIL
10 from rose_v1_repo.fft_structure_extraction import FFTStructureExtraction as structure_extraction
11 import rose2.srv
12 import warnings
13 """
14 Subscribers: /map (nav_msgs/OccupancyGrid)
15 Publishers: /features_ROSE (rose/ROSEFeatures)
16  /clean_map (nav_msgs/OccupancyGrid)
17  /direction_markers (visualization_msgs/MarkerArray)
18 Service: /features_roseSrv (rose2/ROSE)
19 params: /filter -> used for rose method (real number 0 to 1, 0 keeps all the pixels)
20  /pub_once -> publish once or keep publishing at a certain rate (True or False)
21 
22 This node gets a map and applies ROSE method to it. This method is used to find the main directions of the map,
23 and to filter all the pixels which do not belong to the main structure.
24 After computing the result rose publishes ROSEFeatures: main_directions, originalMap and cleanMap
25 The cleanMap corresponds to the original map with non-structural pixels removed, that is, only what is considered to be
26 a wall or part of it is kept in the clean map.
27 """
29  def __init__(self):
30  rospy.init_node('ROSE')
31  rospy.loginfo('[ROSE] waiting for map...')
32  #ROS params
33  self.pubOnce = rospy.get_param("ROSE/pub_once", True)
34  self.filter = rospy.get_param("ROSE/filter", 0.18)
35 
36  #features storing variables
37  self.features = None
38  self.origin = None
39  self.res = None
40  self.imgMap = None
41  self.rose = None
42  self.cleanMapOcc = None
43  #flow control var
44  self.publish = False # True if this node has new features to publish
45 
46  self.pubRate = 1
47 
48  #Service
49  rospy.Service('ROSESrv', rose2.srv.ROSE, self.featuresSrv)
50 
51  #PUBLISHERS
52  self.pubFeatures = rospy.Publisher('features_ROSE', ROSEFeatures, queue_size=1)
53  self.pubCleanMap = rospy.Publisher('clean_map', OccupancyGrid, queue_size=1)
54  self.pubDirections = rospy.Publisher('direction_markers', MarkerArray, queue_size=1)
55  #SUBSCRIBER
56  rospy.Subscriber('map', OccupancyGrid, self.processMap, queue_size=1, buff_size=2**28)
57 
58  def run(self):
59  r = rospy.Rate(self.pubRate)
60  while not rospy.is_shutdown():
61  if self.features is not None and self.publish:
62  self.publishFeatures()
63  if self.pubOnce :
64  self.publish = False
65  r.sleep()
66 
67  #CALLBACK
68  def processMap(self, occMap):
69  self.origin = occMap.info.origin
70  self.res = occMap.info.resolution
71  self.imgMap = mu.fromOccupancyGridToImg(occMap)
72  grid_map = img_as_ubyte(ImagePIL.fromarray(self.imgMap))
73  self.rose = structure_extraction(grid_map, peak_height=0.2, par=50)
74  self.rose.process_map()
75  if len(self.rose.main_directions) > 2:
76  self.rose.simple_filter_map(self.filter)
77  self.rose.generate_initial_hypothesis_simple()
78  try:
79  self.rose.find_walls_flood_filing()
80  except ValueError:
81  rospy.loginfo("[ROSE] skipped data, can't find walls...")
82  return
83  self.analysed_map_uint8 = self.rose.analysed_map.astype(np.uint8)
84  self.main_directions = self.rose.main_directions
85  self.cleanMapOcc = mu.fromImgMapToOccupancyGridRaw(self.analysed_map_uint8, self.origin, self.res)
86  self.features = ROSEFeatures(occMap, self.cleanMapOcc, self.main_directions)
87  rospy.loginfo("[ROSE] DONE.")
88  self.publish = True
89  rospy.loginfo('[ROSE] publishing clean map and main directions')
90  else:
91  rospy.loginfo('[ROSE] skipped data, not enough directions computed...')
92  return
93  def featuresSrv(self, occMap):
94  if(self.features is None):
95  self.processMap(occMap)
96  return self.features
97 
98 
99  def publishFeatures(self):
100  self.pubFeatures.publish(self.features)
101  self.pubCleanMap.publish(self.cleanMapOcc)
102  self.pubDirections.publish(mu.make_direction_markers(self.main_directions, self.origin, self.res))
103 if __name__ == '__main__':
105  warnings.filterwarnings("ignore")
106  f.run()
src.FeatureExtractorROSE.FeatureExtractorROSE.pubDirections
pubDirections
Definition: FeatureExtractorROSE.py:54
src.FeatureExtractorROSE.FeatureExtractorROSE.cleanMapOcc
cleanMapOcc
Definition: FeatureExtractorROSE.py:42
src.FeatureExtractorROSE.FeatureExtractorROSE.processMap
def processMap(self, occMap)
Definition: FeatureExtractorROSE.py:68
src.FeatureExtractorROSE.FeatureExtractorROSE.features
features
Definition: FeatureExtractorROSE.py:37
src.FeatureExtractorROSE.FeatureExtractorROSE.pubOnce
pubOnce
Definition: FeatureExtractorROSE.py:33
src.FeatureExtractorROSE.FeatureExtractorROSE
Definition: FeatureExtractorROSE.py:28
src.FeatureExtractorROSE.FeatureExtractorROSE.res
res
Definition: FeatureExtractorROSE.py:39
src.FeatureExtractorROSE.FeatureExtractorROSE.filter
filter
Definition: FeatureExtractorROSE.py:34
src.FeatureExtractorROSE.FeatureExtractorROSE.pubRate
pubRate
Definition: FeatureExtractorROSE.py:46
src.FeatureExtractorROSE.FeatureExtractorROSE.analysed_map_uint8
analysed_map_uint8
Definition: FeatureExtractorROSE.py:83
src.FeatureExtractorROSE.FeatureExtractorROSE.main_directions
main_directions
Definition: FeatureExtractorROSE.py:84
src.FeatureExtractorROSE.FeatureExtractorROSE.imgMap
imgMap
Definition: FeatureExtractorROSE.py:40
src.FeatureExtractorROSE.FeatureExtractorROSE.publishFeatures
def publishFeatures(self)
Definition: FeatureExtractorROSE.py:99
src.FeatureExtractorROSE.FeatureExtractorROSE.featuresSrv
def featuresSrv(self, occMap)
Definition: FeatureExtractorROSE.py:93
src.FeatureExtractorROSE.FeatureExtractorROSE.pubCleanMap
pubCleanMap
Definition: FeatureExtractorROSE.py:53
src.FeatureExtractorROSE.FeatureExtractorROSE.rose
rose
Definition: FeatureExtractorROSE.py:41
src.FeatureExtractorROSE.FeatureExtractorROSE.run
def run(self)
Definition: FeatureExtractorROSE.py:58
src.FeatureExtractorROSE.FeatureExtractorROSE.origin
origin
Definition: FeatureExtractorROSE.py:38
src.FeatureExtractorROSE.FeatureExtractorROSE.publish
publish
Definition: FeatureExtractorROSE.py:44
src.FeatureExtractorROSE.FeatureExtractorROSE.pubFeatures
pubFeatures
Definition: FeatureExtractorROSE.py:52
src.FeatureExtractorROSE.FeatureExtractorROSE.__init__
def __init__(self)
Definition: FeatureExtractorROSE.py:29


rose2
Author(s): Gabriele Somaschini, Matteo Luperto
autogenerated on Wed Jun 28 2023 02:21:53