Python imgaug.KeypointsOnImage() Examples
The following are 30
code examples of imgaug.KeypointsOnImage().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
imgaug
, or try the search function
.
Example #1
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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
Example #2
Source File: test_batches.py From imgaug with MIT License | 6 votes |
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
Example #3
Source File: check_background_augmentation.py From imgaug with MIT License | 6 votes |
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)
Example #4
Source File: test_lines.py From imgaug with MIT License | 6 votes |
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)])
Example #5
Source File: test_polys.py From imgaug with MIT License | 6 votes |
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)])
Example #6
Source File: test_multicore.py From imgaug with MIT License | 6 votes |
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)
Example #7
Source File: test_bbs.py From imgaug with MIT License | 6 votes |
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
Example #8
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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
Example #9
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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])
Example #10
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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])
Example #11
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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])
Example #12
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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])
Example #13
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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])
Example #14
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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)
Example #15
Source File: test_kps.py From imgaug with MIT License | 6 votes |
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
Example #16
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test___getitem__(self): cbas = [ ia.Keypoint(x=1, y=2), ia.Keypoint(x=2, y=3) ] cbasoi = ia.KeypointsOnImage(cbas, shape=(3, 4, 3)) assert cbasoi[0] is cbas[0] assert cbasoi[1] is cbas[1] assert cbasoi[0:2] == cbas
Example #17
Source File: test_batches.py From imgaug with MIT License | 5 votes |
def test_invert_subselect_rows_by_indices__two_of_three_selected(self): images = np.zeros((3, 3, 4, 1), dtype=np.uint8) images[0, ...] = 0 images[1, ...] = 1 images[2, ...] = 2 batch = _BatchInAugmentation( images=images, 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([0, 2]) batch_sub.images[0, ...] = 10 batch_sub.images[1, ...] = 20 batch_sub.keypoints[0].keypoints[0].x = 10 batch_inv = batch.invert_subselect_rows_by_indices_([0, 2], batch_sub) assert batch_inv.images.shape == (3, 3, 4, 1) assert np.max(batch_inv.images[0]) == 10 assert np.max(batch_inv.images[1]) == 1 assert np.max(batch_inv.images[2]) == 20 assert batch_inv.keypoints[0].keypoints[0].x == 10 assert batch_inv.keypoints[0].keypoints[0].y == 0 assert batch_inv.keypoints[1].keypoints[0].x == 1 assert batch_inv.keypoints[1].keypoints[0].y == 1 assert batch_inv.keypoints[2].keypoints[0].x == 2 assert batch_inv.keypoints[2].keypoints[0].y == 2
Example #18
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_distance_maps_if_not_found_is_dict_thresh_009(self): distance_maps = self._get_distance_maps_for_from_dmap_tests() kpi = ia.KeypointsOnImage.from_distance_maps( distance_maps, if_not_found_coords={"x": 1, "y": 2}, threshold=0.09) assert len(kpi.keypoints) == 2 assert kpi.keypoints[0].x == 2 assert kpi.keypoints[0].y == 2 assert kpi.keypoints[1].x == 1 assert kpi.keypoints[1].y == 2 assert kpi.shape == (4, 5)
Example #19
Source File: test_lines.py From imgaug with MIT License | 5 votes |
def test_invert_to_keypoints_on_image___empty_instance(self): lsoi = ia.LineStringsOnImage([], shape=(1, 2, 3)) kpsoi = ia.KeypointsOnImage([], shape=(10, 20, 30)) lsoi_inv = lsoi.invert_to_keypoints_on_image_(kpsoi) assert len(lsoi_inv.line_strings) == 0 assert lsoi_inv.shape == (10, 20, 30)
Example #20
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test___iter__(self): cbas = [ia.Keypoint(x=1, y=2), ia.Keypoint(x=3, y=4)] cbasoi = ia.KeypointsOnImage(cbas, shape=(40, 50, 3)) for i, cba in enumerate(cbasoi): assert cba is cbas[i]
Example #21
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_distance_maps_if_not_found_is_tuple_thresh_009(self): distance_maps = self._get_distance_maps_for_from_dmap_tests() kpi = ia.KeypointsOnImage.from_distance_maps( distance_maps, if_not_found_coords=(1, 1), threshold=0.09) assert len(kpi.keypoints) == 2 assert kpi.keypoints[0].x == 2 assert kpi.keypoints[0].y == 2 assert kpi.keypoints[1].x == 1 assert kpi.keypoints[1].y == 1 assert kpi.shape == (4, 5)
Example #22
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_distance_maps_inverted(self): distance_maps = self._get_distance_maps_for_from_dmap_tests() distance_maps_inv = np.divide( np.ones_like(distance_maps), distance_maps+1) kpi = ia.KeypointsOnImage.from_distance_maps(distance_maps_inv, inverted=True) assert len(kpi.keypoints) == 2 assert kpi.keypoints[0].x == 2 assert kpi.keypoints[0].y == 2 assert kpi.keypoints[1].x == 4 assert kpi.keypoints[1].y == 2 assert kpi.shape == (4, 5)
Example #23
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_distance_maps_nb_channels_4(self): distance_maps = self._get_distance_maps_for_from_dmap_tests() kpi = ia.KeypointsOnImage.from_distance_maps(distance_maps, nb_channels=4) assert len(kpi.keypoints) == 2 assert kpi.keypoints[0].x == 2 assert kpi.keypoints[0].y == 2 assert kpi.keypoints[1].x == 4 assert kpi.keypoints[1].y == 2 assert kpi.shape == (4, 5, 4)
Example #24
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_to_distance_maps_two_keypoints_inverted(self): kpi = ia.KeypointsOnImage( keypoints=[ia.Keypoint(x=2, y=3), ia.Keypoint(x=1, y=0)], shape=(4, 4, 3)) distance_map_inv = kpi.to_distance_maps(inverted=True) expected = self._get_two_points_keypoint_distance_map() expected_inv = np.divide(np.ones_like(expected), expected+1) assert np.allclose(np.max(distance_map_inv, axis=2), expected_inv)
Example #25
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_to_distance_maps_two_keypoints(self): # TODO this test could have been done a bit better by simply splitting # the distance maps, one per keypoint, considering the function # returns one distance map per keypoint kpi = ia.KeypointsOnImage( keypoints=[ia.Keypoint(x=2, y=3), ia.Keypoint(x=1, y=0)], shape=(4, 4, 3)) distance_map = kpi.to_distance_maps() expected = self._get_two_points_keypoint_distance_map() assert np.allclose(np.min(distance_map, axis=2), expected)
Example #26
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_to_distance_maps_inverted(self): kpi = ia.KeypointsOnImage( keypoints=[ia.Keypoint(x=2, y=3)], shape=(5, 5, 3)) distance_map = kpi.to_distance_maps(inverted=True) expected = self._get_single_keypoint_distance_map() expected_inv = np.divide(np.ones_like(expected), expected+1) assert distance_map.shape == (5, 5, 1) assert np.allclose(distance_map, expected_inv)
Example #27
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_to_distance_maps(self): kpi = ia.KeypointsOnImage( keypoints=[ia.Keypoint(x=2, y=3)], shape=(5, 5, 3)) distance_map = kpi.to_distance_maps() expected = self._get_single_keypoint_distance_map() assert distance_map.shape == (5, 5, 1) assert np.allclose(distance_map, expected)
Example #28
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_keypoint_image_bad_datatype_as_if_not_found(self): kps_image = np.zeros((5, 5, 2), dtype=np.uint8) kps_image[2, 1, 0] = 255 kps_image[4, 3, 1] = 10 with self.assertRaises(Exception) as context: _ = ia.KeypointsOnImage.from_keypoint_image( kps_image, if_not_found_coords="exception-please", threshold=20, nb_channels=3) assert "Expected if_not_found_coords to be" in str(context.exception)
Example #29
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_keypoint_image(self): kps_image = np.zeros((5, 5, 2), dtype=np.uint8) kps_image[2, 1, 0] = 255 kps_image[4, 3, 1] = 255 kpi2 = ia.KeypointsOnImage.from_keypoint_image( kps_image, 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 == 4.5 assert kpi2.keypoints[1].x == 3.5
Example #30
Source File: test_kps.py From imgaug with MIT License | 5 votes |
def test_from_distance_maps_if_not_found_is_none_thresh_009(self): distance_maps = self._get_distance_maps_for_from_dmap_tests() kpi = ia.KeypointsOnImage.from_distance_maps( distance_maps, if_not_found_coords=None, threshold=0.09) assert len(kpi.keypoints) == 1 assert kpi.keypoints[0].x == 2 assert kpi.keypoints[0].y == 2 assert kpi.shape == (4, 5)