2 Commits
2 changed files with 47 additions and 0 deletions

No files matched your search

+12
View File
@@ -29,3 +29,15 @@ def blob_detector(picture):
stars = detector.detect(picture)
result = [star.pt for star in stars]
return result
def relative_coordinates_conversion(coordinates: list[tuple], picture_size: tuple) -> list[tuple] :
if picture_size[0] <= 0 or picture_size[1] <= 0:
raise ValueError(f"({picture_size[0]}, {picture_size[1]}) n'est pas une taille d'image valide.")
denominator = max(picture_size[0], picture_size[1])
converted = []
for i in range(len(coordinates)):
converted.append((
coordinates[i][0] / denominator,
coordinates[i][1] / denominator
))
return converted
+35
View File
@@ -2,6 +2,7 @@ import pytest
import cv2
import numpy as np
from pipeline_b import star_detector
import re
def test_file_exists_and_is_an_image(tmp_path):
file = tmp_path / "image.jpg"
@@ -27,3 +28,37 @@ def test_blob_detector_actually_detects_a_blob():
if abs(star[0] - 23) > 0.001 or abs(star[1] - 31) > 0.001:
assertion = False
assert assertion == True
def test_relative_single_point():
assert star_detector.relative_coordinates_conversion([(23, 31)], (64, 64)) == [(23/64, 31/64)]
def test_relative_several_points_keep_order():
points = [(0, 0), (32, 16), (64, 64)]
assert star_detector.relative_coordinates_conversion(points, (64, 64)) == [(0.0, 0.0), (0.5, 0.25), (1.0, 1.0)]
def test_relative_empty_list():
assert star_detector.relative_coordinates_conversion([], (64, 64)) == []
@pytest.mark.parametrize("size", [(32, 64), (64, 32)])
def test_relative_uses_longest_side_whatever_the_order(size):
# paysage et portrait : même repère (64), donc même résultat
assert star_detector.relative_coordinates_conversion([(16, 16)], size) == [(0.25, 0.25)]
def test_relative_keeps_geometry_on_non_square_image():
# même écart en pixels sur x et y -> même écart en relatif (un cercle reste un cercle)
(x, y), = star_detector.relative_coordinates_conversion([(10, 10)], (32, 64))
assert x == y
def test_relative_non_exact_division_uses_tolerance():
result = star_detector.relative_coordinates_conversion([(100, 250)], (500, 1000))
assert result[0] == pytest.approx((0.1, 0.25))
@pytest.mark.parametrize("size", [(0, 0), (0, 100), (100, 0), (-10, -20), (-1, 64)])
def test_relative_invalid_size_raises_value_error(size):
expected = re.escape(f"({size[0]}, {size[1]})")
with pytest.raises(ValueError, match=expected):
star_detector.relative_coordinates_conversion([(5, 5)], size)
def test_relative_invalid_size_wins_over_empty_list():
with pytest.raises(ValueError):
star_detector.relative_coordinates_conversion([], (0, 0))