本文整理汇总了Python中imgaug.BoundingBox方法的典型用法代码示例。如果您正苦于以下问题:Python imgaug.BoundingBox方法的具体用法?Python imgaug.BoundingBox怎么用?Python imgaug.BoundingBox使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug
的用法示例。
在下文中一共展示了imgaug.BoundingBox方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: example_augment_images_and_bounding_boxes
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def example_augment_images_and_bounding_boxes():
print("Example: Augment Images and Bounding Boxes")
import numpy as np
import imgaug as ia
import imgaug.augmenters as iaa
images = np.zeros((2, 128, 128, 3), dtype=np.uint8) # two example images
images[:, 64, 64, :] = 255
bbs = [
[ia.BoundingBox(x1=10.5, y1=15.5, x2=30.5, y2=50.5)],
[ia.BoundingBox(x1=10.5, y1=20.5, x2=50.5, y2=50.5),
ia.BoundingBox(x1=40.5, y1=75.5, x2=70.5, y2=100.5)]
]
seq = iaa.Sequential([
iaa.AdditiveGaussianNoise(scale=0.05*255),
iaa.Affine(translate_px={"x": (1, 5)})
])
images_aug, bbs_aug = seq(images=images, bounding_boxes=bbs)
示例2: test_non_square_vs_square
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_non_square_vs_square(self):
kpsoi = iadata.quokka_keypoints()
img = iadata.quokka()
patches = []
for kp in kpsoi.keypoints:
bb = ia.BoundingBox(x1=kp.x-1, x2=kp.x+2, y1=kp.y-1, y2=kp.y+2)
patches.append(bb.extract_from_image(img))
img_square = iadata.quokka(extract="square")
kpsoi_square = iadata.quokka_keypoints(extract="square")
assert len(kpsoi.keypoints) == len(kpsoi_square.keypoints)
assert kpsoi_square.shape == (643, 643, 3)
for kp, patch in zip(kpsoi_square.keypoints, patches):
bb = ia.BoundingBox(x1=kp.x-1, x2=kp.x+2, y1=kp.y-1, y2=kp.y+2)
patch_square = bb.extract_from_image(img_square)
assert np.average(
np.abs(
patch.astype(np.float32)
- patch_square.astype(np.float32)
)
) < 1.0
示例3: test_is_out_of_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_is_out_of_image(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40, label=None)
subtests = [
((100, 100, 3), True, True, False),
((100, 100, 3), False, True, False),
((100, 100, 3), True, False, False),
((20, 100, 3), True, True, True),
((20, 100, 3), False, True, False),
((20, 100, 3), True, False, True),
((100, 30, 3), True, True, True),
((100, 30, 3), False, True, False),
((100, 30, 3), True, False, True),
((1, 1, 3), True, True, True),
((1, 1, 3), False, True, True),
((1, 1, 3), True, False, False)
]
for shape, partly, fully, expected in subtests:
with self.subTest(shape=shape, partly=partly, fully=fully):
observed = bb.is_out_of_image(shape,
partly=partly, fully=fully)
assert observed is expected
示例4: test_draw_label_on_image_mocked
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_draw_label_on_image_mocked(self, mock_drawer):
mock_drawer.return_value = mock_drawer
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=1, x1=1, y2=3, x2=3)
result = bb.draw_label_on_image(image)
kwargs = mock_drawer.call_args_list[0][1]
assert kwargs["color"] == (0, 255, 0)
assert kwargs["color_text"] is None
assert kwargs["color_bg"] is None
assert np.isclose(kwargs["alpha"], 1.0)
assert kwargs["size"] == 1
assert kwargs["size_text"] == 20
assert kwargs["height"] == 30
assert kwargs["raise_if_out_of_image"] is False
assert mock_drawer.draw_on_image.call_count == 1
示例5: test_draw_label_on_image_mocked_inplace
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_draw_label_on_image_mocked_inplace(self, mock_drawer):
mock_drawer.return_value = mock_drawer
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=1, x1=1, y2=3, x2=3)
result = bb.draw_label_on_image(image, copy=False)
kwargs = mock_drawer.call_args_list[0][1]
assert kwargs["color"] == (0, 255, 0)
assert kwargs["color_text"] is None
assert kwargs["color_bg"] is None
assert np.isclose(kwargs["alpha"], 1.0)
assert kwargs["size"] == 1
assert kwargs["size_text"] == 20
assert kwargs["height"] == 30
assert kwargs["raise_if_out_of_image"] is False
assert mock_drawer.draw_on_image_.call_count == 1
示例6: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def main():
image = data.astronaut()
image = ia.imresize_single_image(image, (HEIGHT, WIDTH))
kps = []
for y in range(NB_ROWS):
ycoord = BB_Y1 + int(y * (BB_Y2 - BB_Y1) / (NB_COLS - 1))
for x in range(NB_COLS):
xcoord = BB_X1 + int(x * (BB_X2 - BB_X1) / (NB_ROWS - 1))
kp = (xcoord, ycoord)
kps.append(kp)
kps = set(kps)
kps = [ia.Keypoint(x=xcoord, y=ycoord) for (xcoord, ycoord) in kps]
kps = ia.KeypointsOnImage(kps, shape=image.shape)
bb = ia.BoundingBox(x1=BB_X1, x2=BB_X2, y1=BB_Y1, y2=BB_Y2)
bbs = ia.BoundingBoxesOnImage([bb], shape=image.shape)
seq = iaa.Affine(rotate=45)
seq_det = seq.to_deterministic()
image_aug = seq_det.augment_image(image)
kps_aug = seq_det.augment_keypoints([kps])[0]
bbs_aug = seq_det.augment_bounding_boxes([bbs])[0]
image_before = np.copy(image)
image_before = kps.draw_on_image(image_before)
image_before = bbs.draw_on_image(image_before)
image_after = np.copy(image_aug)
image_after = kps_aug.draw_on_image(image_after)
image_after = bbs_aug.draw_on_image(image_after)
ia.imshow(np.hstack([image_before, image_after]))
imageio.imwrite("bb_aug.jpg", np.hstack([image_before, image_after]))
示例7: example_visualize_augmented_non_image_data
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def example_visualize_augmented_non_image_data():
print("Example: Visualize Augmented Non-Image Data")
import numpy as np
import imgaug as ia
image = np.zeros((64, 64, 3), dtype=np.uint8)
# points
kps = [ia.Keypoint(x=10.5, y=20.5), ia.Keypoint(x=60.5, y=60.5)]
kpsoi = ia.KeypointsOnImage(kps, shape=image.shape)
image_with_kps = kpsoi.draw_on_image(image, size=7, color=(0, 0, 255))
ia.imshow(image_with_kps)
# bbs
bbsoi = ia.BoundingBoxesOnImage([
ia.BoundingBox(x1=10.5, y1=20.5, x2=50.5, y2=30.5)
], shape=image.shape)
image_with_bbs = bbsoi.draw_on_image(image)
image_with_bbs = ia.BoundingBox(
x1=50.5, y1=10.5, x2=100.5, y2=16.5
).draw_on_image(image_with_bbs, color=(255, 0, 0), size=3)
ia.imshow(image_with_bbs)
# polygons
psoi = ia.PolygonsOnImage([
ia.Polygon([(10.5, 20.5), (50.5, 30.5), (10.5, 50.5)])
], shape=image.shape)
image_with_polys = psoi.draw_on_image(
image, alpha_points=0, alpha_face=0.5, color_lines=(255, 0, 0))
ia.imshow(image_with_polys)
# heatmaps
# pick first result via [0] here, because one image per heatmap channel
# is generated
hms = ia.HeatmapsOnImage(np.random.random(size=(32, 32, 1)).astype(np.float32),
shape=image.shape)
image_with_hms = hms.draw_on_image(image)[0]
ia.imshow(image_with_hms)
示例8: test_string_square
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_string_square(self):
observed = _quokka_normalize_extract("square")
assert isinstance(observed, ia.BoundingBox)
assert observed.x1 == 0
assert observed.y1 == 0
assert observed.x2 == 643
assert observed.y2 == 643
示例9: test_tuple
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_tuple(self):
observed = _quokka_normalize_extract((1, 1, 644, 642))
assert isinstance(observed, ia.BoundingBox)
assert observed.x1 == 1
assert observed.y1 == 1
assert observed.x2 == 644
assert observed.y2 == 642
示例10: test_boundingboxesonimage
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_boundingboxesonimage(self):
observed = _quokka_normalize_extract(
ia.BoundingBoxesOnImage([
ia.BoundingBox(x1=1, y1=1, x2=644, y2=642)
],
shape=(643, 960, 3)
)
)
assert isinstance(observed, ia.BoundingBox)
assert observed.x1 == 1
assert observed.y1 == 1
assert observed.x2 == 644
assert observed.y2 == 642
示例11: test_project_same_shape
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_project_same_shape(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
bb2 = self._func(bb, (10, 10), (10, 10))
assert np.isclose(bb2.y1, 10)
assert np.isclose(bb2.x1, 20)
assert np.isclose(bb2.y2, 30)
assert np.isclose(bb2.x2, 40)
示例12: test_project_upscale_by_2
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_project_upscale_by_2(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
bb2 = self._func(bb, (10, 10), (20, 20))
assert np.isclose(bb2.y1, 10*2)
assert np.isclose(bb2.x1, 20*2)
assert np.isclose(bb2.y2, 30*2)
assert np.isclose(bb2.x2, 40*2)
示例13: test_project_downscale_by_2
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_project_downscale_by_2(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
bb2 = self._func(bb, (10, 10), (5, 5))
assert np.isclose(bb2.y1, 10*0.5)
assert np.isclose(bb2.x1, 20*0.5)
assert np.isclose(bb2.y2, 30*0.5)
assert np.isclose(bb2.x2, 40*0.5)
示例14: test_project_onto_higher_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_project_onto_higher_image(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
bb2 = self._func(bb, (10, 10), (20, 10))
assert np.isclose(bb2.y1, 10*2)
assert np.isclose(bb2.x1, 20*1)
assert np.isclose(bb2.y2, 30*2)
assert np.isclose(bb2.x2, 40*1)
示例15: test_inplaceness
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import BoundingBox [as 别名]
def test_inplaceness(self):
bb = ia.BoundingBox(y1=10, x1=20, y2=30, x2=40)
bb2 = self._func(bb, (10, 10), (10, 10))
if self._is_inplace:
assert bb2 is bb
else:
assert bb2 is not bb