MCPcopy Create free account
hub / github.com/InternRobotics/EmbodiedScan / ColorMap

Class ColorMap

embodiedscan/visualization/color_selector.py:850–934  ·  view source on GitHub ↗

ColorMap for visualization of EmbodiedScan data and results. Args: classes (list): Category list. init_file (str, optional): The file for initializing the colormap. Defaults to None. verbose (bool): Whether to print related messages. Defaults to False.

Source from the content-addressed store, hash-verified

848
849
850class ColorMap(object):
851 """ColorMap for visualization of EmbodiedScan data and results.
852
853 Args:
854 classes (list): Category list.
855 init_file (str, optional): The file for initializing the colormap.
856 Defaults to None.
857 verbose (bool): Whether to print related messages. Defaults to False.
858 """
859
860 def __init__(self, classes=EMBODIED_CATE, init_file=None, verbose=False):
861 self.color_map = dict()
862 self.verbose = verbose
863 if init_file is not None:
864 with open(init_file, 'r') as f:
865 pre_data = f.readlines()
866 for ins in pre_data:
867 s = ins.strip()
868 cate = s.split('[')[0].strip()
869 color = eval(s[len(cate):])
870 self.color_map[cate] = color
871 else:
872 from .default_color_map import DEFAULT_COLOR_MAP
873 self.color_map = DEFAULT_COLOR_MAP
874
875 self.classes = classes
876 self.color_pool = COCO_COLOR
877
878 for label in classes:
879 if label not in self.color_map:
880 x = random.choice(self.color_pool)
881 self.color_map[label] = x['color']
882
883 self.inv_color_map = dict()
884 for key, value in self.color_map.items():
885 color_idx = value[0] * 256 * 256 + value[1] * 256 + value[2]
886 if color_idx in self.inv_color_map:
887 self.inv_color_map[color_idx].append(key)
888 else:
889 self.inv_color_map[color_idx] = [key]
890
891 self.visible_label = set()
892
893 def save(self, out_file):
894 """Save the colormap to the output path.
895
896 Args:
897 out_file (str): Output path for saving the colormap.
898 """
899 with open(out_file, 'w') as f:
900 for key, value in self.color_map.items():
901 print(key, value, file=f)
902
903 def get_color(self, label):
904 """Get the color of a given category label.
905
906 Args:
907 label (str): Category name.

Callers 2

__init__Method · 0.90
color_selector.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected