本文整理汇总了Python中utils.boxes.xywh_to_xyxy方法的典型用法代码示例。如果您正苦于以下问题:Python boxes.xywh_to_xyxy方法的具体用法?Python boxes.xywh_to_xyxy怎么用?Python boxes.xywh_to_xyxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.boxes
的用法示例。
在下文中一共展示了boxes.xywh_to_xyxy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_gt_annotations
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import xywh_to_xyxy [as 别名]
def _add_gt_annotations(self, entry):
"""Add ground truth annotation metadata to an roidb entry."""
ann_ids = self.COCO.getAnnIds(imgIds=entry['id'], iscrowd=None)
objs = self.COCO.loadAnns(ann_ids)
# Sanitize bboxes -- some are invalid
valid_objs = []
valid_segms = []
width = entry['width']
height = entry['height']
for obj in objs:
# crowd regions are RLE encoded and stored as dicts
if obj['area'] < cfg.TRAIN.GT_MIN_AREA:
continue
if 'ignore' in obj and obj['ignore'] == 1:
continue
# Convert form (x1, y1, w, h) to (x1, y1, x2, y2)
x1, y1, x2, y2 = box_utils.xywh_to_xyxy(obj['bbox'])
x1, y1, x2, y2 = box_utils.clip_xyxy_to_image(
x1, y1, x2, y2, height, width
)
# Require non-zero seg area and more than 1x1 box size
if obj['area'] > 0 and x2 > x1 and y2 > y1:
obj['clean_bbox'] = [x1, y1, x2, y2]
valid_objs.append(obj)
num_valid_objs = len(valid_objs)
gt_classes = np.zeros((num_valid_objs), dtype=entry['gt_classes'].dtype)
for ix, obj in enumerate(valid_objs):
cls = self.json_category_id_to_contiguous_id[obj['category_id']]
gt_classes[ix] = cls
for cls in gt_classes:
entry['gt_classes'][0, cls] = 1
示例2: test_bbox_dataset_to_prediction_roundtrip
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import xywh_to_xyxy [as 别名]
def test_bbox_dataset_to_prediction_roundtrip(self):
"""Simulate the process of reading a ground-truth box from a dataset,
make predictions from proposals, convert the predictions back to the
dataset format, and then use the COCO API to compute IoU overlap between
the gt box and the predictions. These should have IoU of 1.
"""
weights = (5, 5, 10, 10)
# 1/ "read" a box from a dataset in the default (x1, y1, w, h) format
gt_xywh_box = [10, 20, 100, 150]
# 2/ convert it to our internal (x1, y1, x2, y2) format
gt_xyxy_box = box_utils.xywh_to_xyxy(gt_xywh_box)
# 3/ consider nearby proposal boxes
prop_xyxy_boxes = random_boxes(gt_xyxy_box, 10, 10)
# 4/ compute proposal-to-gt transformation deltas
deltas = box_utils.bbox_transform_inv(
prop_xyxy_boxes, np.array([gt_xyxy_box]), weights=weights
)
# 5/ use deltas to transform proposals to xyxy predicted box
pred_xyxy_boxes = box_utils.bbox_transform(
prop_xyxy_boxes, deltas, weights=weights
)
# 6/ convert xyxy predicted box to xywh predicted box
pred_xywh_boxes = box_utils.xyxy_to_xywh(pred_xyxy_boxes)
# 7/ use COCO API to compute IoU
not_crowd = [int(False)] * pred_xywh_boxes.shape[0]
ious = COCOmask.iou(pred_xywh_boxes, np.array([gt_xywh_box]), not_crowd)
np.testing.assert_array_almost_equal(ious, np.ones(ious.shape))
示例3: save_im_masks
# 需要导入模块: from utils import boxes [as 别名]
# 或者: from utils.boxes import xywh_to_xyxy [as 别名]
def save_im_masks(im, M, id, dir):
from utils.boxes import xywh_to_xyxy
import os
try:
os.mkdir(os.path.join('vis', dir))
except:
pass
M[M > 0] = 1
aug_rles = mask_util.encode(np.asarray(M, order='F'))
boxes = xywh_to_xyxy(np.asarray(mask_util.toBbox(aug_rles)))
boxes = np.append(boxes, np.ones((len(boxes), 2)), 1)
from utils.vis import vis_one_image
vis_one_image(im, str(id), os.path.join('vis', dir), boxes, segms=aug_rles, keypoints=None, thresh=0.9,box_alpha=0.8, show_class=False,)