43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
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
|
|
params.filterByColor = True
|
|
params.blobColor = 255
|
|
# TODO: valeurs provisoires, à recalibrer avec de vraies images de test
|
|
detector = cv2.SimpleBlobDetector.create(params)
|
|
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 |