本文整理汇总了Python中imgaug.Keypoint方法的典型用法代码示例。如果您正苦于以下问题:Python imgaug.Keypoint方法的具体用法?Python imgaug.Keypoint怎么用?Python imgaug.Keypoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imgaug
的用法示例。
在下文中一共展示了imgaug.Keypoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [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 Keypoint [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 Keypoint [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 Keypoint [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_one_kp_at_bottom_right_corner
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [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])
示例6: test_draw_on_image_one_kp_at_bottom_right_corner_and_raise_true
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [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)
示例7: apply_coords
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def apply_coords(self, coords):
import imgaug as IA
points = [IA.Keypoint(x=x, y=y) for x, y in coords]
points = IA.KeypointsOnImage(points, shape=self.img_shape)
augmented = self.aug.augment_keypoints([points])[0].keypoints
return np.asarray([[p.x, p.y] for p in augmented])
示例8: main
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [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]))
示例9: example_visualize_augmented_non_image_data
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [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)
示例10: load_images
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def load_images(n_batches=10, sleep=0.0, draw_text=True):
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):
if draw_text:
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
)
else:
if i == 0:
batch_images = np.array([np.copy(astronaut) for _ in range(batch_size)], dtype=np.uint8)
batch = ia.Batch(
images=np.copy(batch_images),
keypoints=[kps.deepcopy() for _ in range(batch_size)]
)
yield batch
if sleep > 0:
time.sleep(sleep)
示例11: create_random_keypoints
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def create_random_keypoints(size_images, nb_keypoints_per_img):
result = []
for _ in sm.xrange(size_images[0]):
kps = []
height, width = size_images[1], size_images[2]
for _ in sm.xrange(nb_keypoints_per_img):
x = np.random.randint(0, width-1)
y = np.random.randint(0, height-1)
kps.append(ia.Keypoint(x=x, y=y))
result.append(ia.KeypointsOnImage(kps, shape=size_images[1:]))
return result
示例12: test_project_same_image_size
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def test_project_same_image_size(self):
kp = ia.Keypoint(y=1, x=2)
kp2 = self._func(kp, (10, 10), (10, 10))
assert kp2.y == 1
assert kp2.x == 2
示例13: test_project_onto_higher_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def test_project_onto_higher_image(self):
kp = ia.Keypoint(y=1, x=2)
kp2 = self._func(kp, (10, 10), (20, 10))
assert kp2.y == 2
assert kp2.x == 2
示例14: test_project_onto_wider_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def test_project_onto_wider_image(self):
kp = ia.Keypoint(y=1, x=2)
kp2 = self._func(kp, (10, 10), (10, 20))
assert kp2.y == 1
assert kp2.x == 4
示例15: test_project_onto_higher_and_wider_image
# 需要导入模块: import imgaug [as 别名]
# 或者: from imgaug import Keypoint [as 别名]
def test_project_onto_higher_and_wider_image(self):
kp = ia.Keypoint(y=1, x=2)
kp2 = self._func(kp, (10, 10), (20, 20))
assert kp2.y == 2
assert kp2.x == 4