Exemplo n.º 1
0
 def _parse_keypoints_skeleton(self, image_filename):
     keypoints, skeleton = [], []
     if self.anno_type == 'keypoints':
         img_id = dataset_util.get_image_id(image_filename)
         mask_file = self.get_src_label_filepath(img_id)
         mask_anno = JsonParserIO.from_file(mask_file)
         keypoints, skeleton = mask_anno.keypoints, mask_anno.skeleton
     return keypoints, skeleton
Exemplo n.º 2
0
    def generate_labels(self, image_list, label_intervals):
        logging.info('generate segmentation ...')
        label_list = []
        mode = 'SegmentationClassAug'
        for srcfile in tqdm(
                image_list[label_intervals[mode][0]:label_intervals[mode][1]]):
            img_id = dataset_util.get_image_id(srcfile)
            self._gen_seg_obj(img_id, label_list)

        mode = 'SegmentationClass'
        for srcfile in tqdm(
                image_list[label_intervals[mode][0]:label_intervals[mode][1]]):
            img_id = dataset_util.get_image_id(srcfile)
            self._gen_mask_image_with_palette(img_id)

        logging.info('label list {0}'.format(label_list))
        dataset_util.write_label_id_color_file(label_list,
                                               self.paths['output'])
Exemplo n.º 3
0
    def _build_label_infos(self, image_list, intervals):
        label_list = []
        keypoints, skeleton = self._parse_keypoints_skeleton(image_list[0])
        for mode in self.label_modes:
            for i in tqdm(range(intervals[mode][0], intervals[mode][1])):
                img_id = dataset_util.get_image_id(image_list[i])
                self._parse_single_label_file(img_id, mode, label_list,
                                              keypoints, skeleton)

        return label_list, keypoints, skeleton
Exemplo n.º 4
0
 def _copy_images_per_mode(self, src_path, images_sublist, mode, dest_path):
     for srcfile in tqdm(images_sublist):
         img_id = dataset_util.get_image_id(srcfile)
         img_in = cv2.imread(os.path.join(src_path, srcfile))
         if img_in is None:
             print('Failed to read image file', srcfile)
             continue
         new_name = self.get_dest_mode_filename(mode, img_id)
         area = dataset_util.get_area(img_in.shape, *self.get_image_size())
         dataset_util.copy_image(area, img_in,
                                 os.path.join(dest_path, new_name),
                                 self.background_color)
Exemplo n.º 5
0
    def generate_labels(self, image_list, label_intervals):
        print('generate labels ...')
        label_list = []
        for image_mode in self.image_modes:
            for i in range(label_intervals[image_mode][0],
                           label_intervals[image_mode][1]):
                img_id = dataset_util.get_image_id(image_list[i])
                label_mode = image_mode.replace(self.image_folder,
                                                self.label_folder)
                self.generate_labels_per_mode(label_mode, img_id, label_list)

        dataset_util.write_label_id_color_file(label_list,
                                               self.get_root_path())
        print('cityscape format done')
Exemplo n.º 6
0
 def _copy_depth_per_mode(self, src_path, images_sublist, mode, dest_path):
     for srcfile in tqdm(images_sublist):
         img_id = dataset_util.get_image_id(srcfile)
         depth_srcfile = dataset_util.get_same_name_file(src_path, srcfile)
         img_in = cv2.imread(os.path.join(src_path, depth_srcfile),
                             cv2.IMREAD_UNCHANGED)
         if img_in is None:
             print('Failed to read depth file', srcfile)
             continue
         new_name = self.get_dest_mode_filename(
             mode, img_id, suffix=os.path.splitext(depth_srcfile)[1])
         area = dataset_util.get_area(img_in.shape, *self.get_image_size())
         dataset_util.copy_image(area, img_in,
                                 os.path.join(dest_path, new_name),
                                 self.background_color)
Exemplo n.º 7
0
 def write_file_list(self, image_list, split_intervals):
     for image_mode in self.image_modes:
         images_sublist = image_list[
             split_intervals[image_mode][0]:split_intervals[image_mode][1]]
         imglist_file_lines = []
         for srcfile in images_sublist:
             img_id = dataset_util.get_image_id(srcfile)
             origin_img_path = self.get_cs_relative_image_path(
                 image_mode, img_id)
             label_mode = image_mode.replace(self.image_folder,
                                             self.label_folder)
             gtFine_img_path = self.get_cs_relative_gtFine_mask_path(
                 label_mode, img_id)
             imglist_single_line = str(
                 self._images_num
             ) + '\t' + origin_img_path + '\t' + gtFine_img_path + '\n'
             imglist_file_lines.append(imglist_single_line)
             self._images_num += 1
         split_mode = image_mode.replace(self.image_folder,
                                         self.split_folder)
         with open(self.get_cs_imglist_filepath(split_mode), 'w') as f_lst:
             f_lst.writelines(imglist_file_lines)
Exemplo n.º 8
0
 def _build_image_infos(self, image_list, intervals):
     for split_type in self.label_modes:
         for i in range(intervals[split_type][0], intervals[split_type][1]):
             img_id = dataset_util.get_image_id(image_list[i])
             image_msg = self._set_image_msg(img_id, split_type)
             self._images[split_type].append(image_msg)