控制邊框邊界溢出代碼



def _load_pascal_annotation(self, index):

	 #Load image and bounding boxes info from XML file in the PASCAL VOC format  
	 #翻譯:以PASCAL VOC格式從XML文件中加載圖像和邊框信息
	 
     filename = os.path.join(self._data_path, 'Annotations', index + '.xml')
     tree = ET.parse(filename)
     objs = tree.findall('object')
     size = tree.find('size')
     width = size.find('width').text
     height = size.find('height').text
     print(width, height)
     num_objs = len(objs)

     boxes = np.zeros((num_objs, 4), dtype=np.unit16)
     gt_classes = np.zeros((num_objs), dtype=np.int32)
     overlaps = np.zeros((num_objs, self.num_classes), dtype=np.float32)
     
     # "Seg" area for pascal is just the box area   翻譯:pascal的“Seg”區域就是方框區域
     seg_areas = np.zeros((num_objs), dtype=np.float32)

     # Load object bounding boxes into a data frame   翻譯:將對象包圍框加載到數據幀中
     for ix, obj in enumerate(objs):

          clsname = obj.find('name').text.lower().strip()
          bbox = obj.find('bndbox')
          
          # Make pixel indexes 0-based   翻譯:使像素索引基於0
          x1 = max(float(bbox.find('xmin').text - 1), 0)
          y1 = max(float(bbox.find('ymin').text - 1), 0)
          x2 = min(float(bbox.find('xmax').text), float(width))
          y2 = min(float(bbox.find('ymax').text), float(height))

          if x1 > x2: x1 = x2
          if y1 > y2: y1 = y2

          cls = self._classes_to_ind[clsname]
          boxes[ix, :] = [x1, y1, x2, y2]
          seg_areas[ix] = (x2 - x1 + 1) * (y2 - y1 + 1)
          gt_classes[ix] = cls
          overlaps[ix, cls] = 1.0

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章