From 6af462858bf5d0f33f3111b8965d3f549de30414 Mon Sep 17 00:00:00 2001 From: vohorgeez Date: Tue, 1 Sep 2026 01:03:17 +0200 Subject: [PATCH] feat(pipeline-b): ajout de reading_picture et blob_detector avec tests partiels --- conftest.py | 0 pipeline_b/star_detector.py | 29 +++++++++++++++++++++++++++++ requirements.txt | Bin 80 -> 280 bytes tests/tests_pipeline_b.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 conftest.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/pipeline_b/star_detector.py b/pipeline_b/star_detector.py index e69de29..0887deb 100644 --- a/pipeline_b/star_detector.py +++ b/pipeline_b/star_detector.py @@ -0,0 +1,29 @@ +import numpy as np # Je le laisse pour plus tard +import cv2 +import os + +def reading_picture(path): + if not os.path.exists(path): + raise FileNotFoundError(f"{path} n'existe pas.") + pic = cv2.imread(path, cv2.IMREAD_GRAYSCALE) + if pic is None: + raise ValueError(f"{path} est corrompu ou n'est pas une image valide.") + return pic + +def blob_detector(picture): + params = cv2.SimpleBlobDetector_Params() + params.minThreshold = 10 + params.maxThreshold = 200 + params.filterByArea = True + params.minArea = 4 + params.filterByCircularity = True + params.minCircularity = 0.1 + params.filterByConvexity = True + params.minConvexity = 0.87 + params.filterByInertia = True + params.minInertiaRatio = 0.01 + # TODO: valeurs provisoires, à recalibrer avec de vraies images de test cette semaine. + detector = cv2.SimpleBlobDetector.create(params) + stars = detector.detect(picture) + result = [star.pt for star in stars] + return result \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5a99242e5ecceac197123ecf024f12edba59a48c..f1105afcbf5a6099fbaf0387784355a75b73232b 100644 GIT binary patch literal 280 zcmX|*Q3}E^5Jcx&@F+@Kwa^dm;1wij6l+>+D|mVJ?S__RLfCo9%;O31jRE4S!Og}+0EGf5M#dwmw~fLFQKvA^&(=&g-2qi+72Wf^CAriLFa zv8PASgEM;ioLIxmL`!01a$<>NZfz51F1R Al>h($ delta 9 QcmbQi6u|WV-$V~T0246;5dZ)H diff --git a/tests/tests_pipeline_b.py b/tests/tests_pipeline_b.py index e69de29..b37b45c 100644 --- a/tests/tests_pipeline_b.py +++ b/tests/tests_pipeline_b.py @@ -0,0 +1,29 @@ +import pytest +import cv2 +import numpy as np +from pipeline_b import star_detector + +def test_file_exists_and_is_an_image(tmp_path): + file = tmp_path / "image.jpg" + tableau_image = np.random.randint(0, 256, (64, 64), dtype=np.uint8) + cv2.imwrite(str(file), tableau_image) + assert isinstance(star_detector.reading_picture(file), np.ndarray) + +def test_file_exists_not_an_image(tmp_path): + file = tmp_path / "file.txt" + file.write_text("Not an image.") + with pytest.raises(ValueError): + star_detector.reading_picture(file) + +def test_file_does_not_exists(tmp_path): + with pytest.raises(FileNotFoundError): + star_detector.reading_picture(tmp_path/"do_I_exist.txt") + +@pytest.mark.skip(reason="A corriger : égalité stricte sur flottants, canall couleur incohérent, détour disque inutile") +def test_blob_detector_actually_detects_a_blob(tmp_path): + file = tmp_path / "image.jpg" + tableau_image = np.full((64,64), 0, dtype=np.uint8) + cv2.imwrite(str(file), tableau_image) + src = cv2.imread(file) + cv2.circle(src, center=(23, 31), radius = 5, color= (255, 255, 255), thickness=-1) + assert star_detector.blob_detector(src) == [(23, 31)] \ No newline at end of file