本文整理汇总了Python中imgaug.KeypointsOnImage方法的典型用法代码示例。如果您正苦于以下问题:Python imgaug.KeypointsOnImage方法的具体用法?Python imgaug.KeypointsOnImage怎么用?Python imgaug.KeypointsOnImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug
的用法示例。
在下文中一共展示了imgaug.KeypointsOnImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def load_images(n_batches=10, sleep=0.0):
batch_size = 4
astronaut = data.astronaut()
astronaut = ia.imresize_single_image(astronaut, (64, 64))
kps = ia.KeypointsOnImage([ia.Keypoint(x=15, y=25)], shape=astronaut.shape)
counter = 0
for i in range(n_batches):
batch_images = []
batch_kps = []
for b in range(batch_size):
astronaut_text = ia.draw_text(astronaut, x=0, y=0, text="%d" % (counter,), color=[0, 255, 0], size=16)
batch_images.append(astronaut_text)
batch_kps.append(kps)
counter += 1
batch = ia.Batch(
images=np.array(batch_images, dtype=np.uint8),
keypoints=batch_kps
)
yield batch
if sleep > 0:
time.sleep(sleep)
示例2: test_draw_on_image_alpha_is_50_percent
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_alpha_is_50_percent(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
image_kps = kpi.draw_on_image(
image, color=[0, 255, 0], alpha=0.5, size=1, copy=True,
raise_if_out_of_image=False)
bg_plus_color_at_alpha = [int(0.5*10+0),
int(0.5*10+0.5*255),
int(10*0.5+0)]
assert np.all(image_kps[kps_mask] == bg_plus_color_at_alpha)
assert np.all(image_kps[~kps_mask] == [10, 10, 10])
示例3: test_draw_on_image_size_3
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_size_3(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
image_kps = kpi.draw_on_image(
image, color=[0, 255, 0], size=3, copy=True,
raise_if_out_of_image=False)
kps_mask_size3 = np.copy(kps_mask)
kps_mask_size3[2-1:2+1+1, 1-1:1+1+1] = 1
kps_mask_size3[4-1:4+1+1, 3-1:3+1+1] = 1
assert np.all(image_kps[kps_mask_size3] == [0, 255, 0])
assert np.all(image_kps[~kps_mask_size3] == [10, 10, 10])
示例4: test_draw_on_image_copy_is_false
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_copy_is_false(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
image2 = np.copy(image)
image_kps = kpi.draw_on_image(
image2, color=[0, 255, 0], size=1, copy=False,
raise_if_out_of_image=False)
assert np.all(image2 == image_kps)
assert np.all(image_kps[kps_mask] == [0, 255, 0])
assert np.all(image_kps[~kps_mask] == [10, 10, 10])
assert np.all(image2[kps_mask] == [0, 255, 0])
assert np.all(image2[~kps_mask] == [10, 10, 10])
示例5: test_draw_on_image_keypoint_is_outside_of_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_keypoint_is_outside_of_image(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(
keypoints=kps + [ia.Keypoint(x=100, y=100)],
shape=(5, 5, 3)
)
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
image_kps = kpi.draw_on_image(
image, color=[0, 255, 0], size=1, copy=True,
raise_if_out_of_image=False)
assert np.all(image_kps[kps_mask] == [0, 255, 0])
assert np.all(image_kps[~kps_mask] == [10, 10, 10])
示例6: test_draw_on_image_one_kp_at_bottom_right_corner
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_one_kp_at_bottom_right_corner(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(
keypoints=kps + [ia.Keypoint(x=5, y=5)],
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
image_kps = kpi.draw_on_image(
image, color=[0, 255, 0], size=1, copy=True,
raise_if_out_of_image=False)
assert np.all(image_kps[kps_mask] == [0, 255, 0])
assert np.all(image_kps[~kps_mask] == [10, 10, 10])
示例7: test_draw_on_image_one_kp_at_bottom_right_corner_and_raise_true
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_draw_on_image_one_kp_at_bottom_right_corner_and_raise_true(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(
keypoints=kps + [ia.Keypoint(x=5, y=5)],
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1
with self.assertRaises(Exception) as context:
_ = kpi.draw_on_image(
image, color=[0, 255, 0], size=1, copy=True,
raise_if_out_of_image=True)
assert "Cannot draw keypoint" in str(context.exception)
示例8: test_from_keypoint_image_dict_as_if_not_found_thresh_20
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_from_keypoint_image_dict_as_if_not_found_thresh_20(self):
kps_image = np.zeros((5, 5, 2), dtype=np.uint8)
kps_image[2, 1, 0] = 255
kps_image[4, 3, 1] = 10
kpi2 = ia.KeypointsOnImage.from_keypoint_image(
kps_image,
if_not_found_coords={"x": -1, "y": -2},
threshold=20,
nb_channels=3)
assert kpi2.shape == (5, 5, 3)
assert len(kpi2.keypoints) == 2
assert kpi2.keypoints[0].y == 2.5
assert kpi2.keypoints[0].x == 1.5
assert kpi2.keypoints[1].y == -2
assert kpi2.keypoints[1].x == -1
示例9: test_from_keypoint_image_tuple_as_if_not_found_thresh_20
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_from_keypoint_image_tuple_as_if_not_found_thresh_20(self):
kps_image = np.zeros((5, 5, 2), dtype=np.uint8)
kps_image[2, 1, 0] = 255
kps_image[4, 3, 1] = 10
kpi2 = ia.KeypointsOnImage.from_keypoint_image(
kps_image,
if_not_found_coords=(-1, -2),
threshold=20,
nb_channels=3)
assert kpi2.shape == (5, 5, 3)
assert len(kpi2.keypoints) == 2
assert kpi2.keypoints[0].y == 2.5
assert kpi2.keypoints[0].x == 1.5
assert kpi2.keypoints[1].y == -2
assert kpi2.keypoints[1].x == -1
示例10: test_copy
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_copy(self):
kps = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)]
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
kpi2 = kpi.copy()
assert kpi2.keypoints[0].x == 1
assert kpi2.keypoints[0].y == 2
assert kpi2.keypoints[1].x == 3
assert kpi2.keypoints[1].y == 4
kps[0].x = 100
assert kpi2.keypoints[0].x == 100
assert kpi2.keypoints[0].y == 2
assert kpi2.keypoints[1].x == 3
assert kpi2.keypoints[1].y == 4
示例11: test_invert_to_keypoints_on_image_
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_invert_to_keypoints_on_image_(self):
bbsoi = ia.BoundingBoxesOnImage(
[ia.BoundingBox(0, 1, 2, 3),
ia.BoundingBox(10, 20, 30, 40)],
shape=(1, 2, 3))
kpsoi = ia.KeypointsOnImage(
[ia.Keypoint(100, 101), ia.Keypoint(102, 103),
ia.Keypoint(104, 105), ia.Keypoint(106, 107),
ia.Keypoint(110, 120), ia.Keypoint(130, 140),
ia.Keypoint(150, 160), ia.Keypoint(170, 180)],
shape=(10, 20, 30))
bbsoi_inv = bbsoi.invert_to_keypoints_on_image_(kpsoi)
assert len(bbsoi_inv.bounding_boxes) == 2
assert bbsoi_inv.shape == (10, 20, 30)
assert bbsoi_inv.bounding_boxes[0].x1 == 100
assert bbsoi_inv.bounding_boxes[0].y1 == 101
assert bbsoi_inv.bounding_boxes[0].x2 == 106
assert bbsoi_inv.bounding_boxes[0].y2 == 107
assert bbsoi_inv.bounding_boxes[1].x1 == 110
assert bbsoi_inv.bounding_boxes[1].y1 == 120
assert bbsoi_inv.bounding_boxes[1].x2 == 170
assert bbsoi_inv.bounding_boxes[1].y2 == 180
示例12: test_subselect_rows_by_indices__none_selected
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_subselect_rows_by_indices__none_selected(self):
batch = _BatchInAugmentation(
images=np.zeros((3, 3, 4, 1)),
keypoints=[
ia.KeypointsOnImage(
[ia.Keypoint(0, 0)],
shape=(3, 4, 1)
),
ia.KeypointsOnImage(
[ia.Keypoint(1, 1)],
shape=(3, 4, 1)
),
ia.KeypointsOnImage(
[ia.Keypoint(2, 2)],
shape=(3, 4, 1)
)
]
)
batch_sub = batch.subselect_rows_by_indices([])
assert batch_sub.images is None
assert batch_sub.keypoints is None
示例13: test_invert_to_keypoints_on_image_
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_invert_to_keypoints_on_image_(self):
lsoi = ia.LineStringsOnImage(
[ia.LineString([(0, 0), (1, 2)]),
ia.LineString([(10, 20), (30, 40)])],
shape=(1, 2, 3))
kpsoi = ia.KeypointsOnImage(
[ia.Keypoint(100, 101), ia.Keypoint(102, 103),
ia.Keypoint(110, 120), ia.Keypoint(130, 140)],
shape=(10, 20, 30))
lsoi_inv = lsoi.invert_to_keypoints_on_image_(kpsoi)
assert len(lsoi_inv.line_strings) == 2
assert lsoi_inv.shape == (10, 20, 30)
assert np.allclose(
lsoi.line_strings[0].coords,
[(100, 101), (102, 103)])
assert np.allclose(
lsoi.line_strings[1].coords,
[(110, 120), (130, 140)])
示例14: test_filled_instance
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_filled_instance(self):
psoi = ia.PolygonsOnImage(
[ia.Polygon([(0, 0), (1, 0), (1, 1)]),
ia.Polygon([(10, 10), (20, 0), (20, 20)])],
shape=(1, 2, 3))
kpsoi = ia.KeypointsOnImage(
[ia.Keypoint(100, 100), ia.Keypoint(101, 100),
ia.Keypoint(101, 101),
ia.Keypoint(110, 110), ia.Keypoint(120, 100),
ia.Keypoint(120, 120)],
shape=(10, 20, 30))
psoi_inv = psoi.invert_to_keypoints_on_image_(kpsoi)
assert len(psoi_inv.polygons) == 2
assert psoi_inv.shape == (10, 20, 30)
assert np.allclose(
psoi.polygons[0].coords,
[(100, 100), (101, 100), (101, 101)])
assert np.allclose(
psoi.polygons[1].coords,
[(110, 110), (120, 100), (120, 120)])
示例15: test_augmentations_without_seed_differ_for_images_and_keypoints
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import KeypointsOnImage [as 别名]
def test_augmentations_without_seed_differ_for_images_and_keypoints(self):
augseq = iaa.AddElementwise((0, 255))
image = np.zeros((10, 10, 1), dtype=np.uint8)
# keypoints here will not be changed by augseq, but they will
# induce deterministic mode to start in augment_batches() as each
# batch contains images AND keypoints
kps = ia.KeypointsOnImage([ia.Keypoint(x=2, y=0)], shape=(10, 10, 1))
batch = ia.Batch(images=np.uint8([image, image]), keypoints=[kps, kps])
batches = [batch.deepcopy() for _ in sm.xrange(20)]
with multicore.Pool(augseq, processes=2, maxtasksperchild=5) as pool:
batches_aug = pool.map_batches(batches, chunksize=2)
with multicore.Pool(augseq, processes=2) as pool:
batches_aug.extend(pool.map_batches(batches, chunksize=1))
assert len(batches_aug) == 2*20
for batch in batches_aug:
for keypoints_aug in batch.keypoints_aug:
assert keypoints_aug.keypoints[0].x == 2
assert keypoints_aug.keypoints[0].y == 0
self._assert_each_augmentation_not_more_than_once(batches_aug)