def test_point_alignment_without_normalization(self): image = np.random.randint(0, 255, (40, 40, 3)).astype(np.uint8) point_aligner = PointAligner({'type': 'point_alignment', 'dst_width': 40, 'dst_height': 40, 'normalize': False}) result = point_aligner( DataRepresentation(image), {'keypoints': PointAligner.ref_landmarks.reshape(-1).tolist()} ).data transformation_matrix = point_aligner.transformation_from_points( point_aligner.ref_landmarks * 40, point_aligner.ref_landmarks * 40 ) expected_result = cv2.warpAffine(image, transformation_matrix, (40, 40), flags=cv2.WARP_INVERSE_MAP) assert np.array_equal(result, expected_result)
def test_point_alignment_to_negative_destination_height_raise_config_error( self): with pytest.raises(ValueError): PointAligner({ 'type': 'point_alignment', 'dst_width': 100, 'dst_height': -100 })
def test_point_alignment_both_provided_size_and_dst_height_dst_width_warn(self): input_image = np.ones((100, 50, 3)) with pytest.warns(None) as warnings: point_aligner = PointAligner({'type': 'point_alignment', 'dst_width': 100, 'dst_height': 100, 'size': 200}) assert len(warnings) == 1 result = point_aligner(DataRepresentation(input_image), {}).data assert result.shape == (100, 50, 3)
def test_point_alignment_with_drawing_points(self): image = np.random.randint(0, 255, (40, 40, 3)).astype(np.uint8) point_aligner = PointAligner({ 'type': 'point_alignment', 'dst_width': 40, 'dst_height': 40, 'draw_points': True }) result = point_aligner( DataRepresentation(image), {'keypoints': PointAligner.ref_landmarks.reshape(-1).tolist()} ).data transformation_matrix = point_aligner.transformation_from_points( point_aligner.ref_landmarks * 40, point_aligner.ref_landmarks ) expected_result = image for point in PointAligner.ref_landmarks: cv2.circle(expected_result, (int(point[0]), int(point[1])), 5, (255, 0, 0), -1) expected_result = cv2.warpAffine(expected_result, transformation_matrix, (40, 40), flags=cv2.WARP_INVERSE_MAP) assert np.array_equal(result, expected_result)
def test_point_alignment_not_provided_points_im_meta(self): input_image = np.ones((100, 50, 3)) point_aligner = PointAligner({ 'type': 'point_alignment', 'dst_width': 100, 'dst_height': 100 }) result = point_aligner(DataRepresentation(input_image), {}).data assert result.shape == (100, 50, 3)
def test_point_alignment_provided_only_dst_width_raise_config_error(self): with pytest.raises(ValueError): PointAligner({'type': 'point_alignment', 'dst_width': 100})
def test_point_alignment_width_negative_size_raise_config_error(self): with pytest.raises(ConfigError): PointAligner({'type': 'point_alignment', 'size': -100})