Amélioration résultat console

This commit is contained in:
yanis.bouarfa 2025-01-07 23:49:18 +01:00
parent 922b9acf18
commit 6da377d7c5
3 changed files with 16 additions and 7 deletions

10
main.py
View file

@ -3,7 +3,7 @@ from src.pipeline import ObjectDetectionPipeline
from src.classifiers.bayesian import BayesianClassifier from src.classifiers.bayesian import BayesianClassifier
# Définissez le mode d'analyse ici : "plan" ou "page" # Définissez le mode d'analyse ici : "plan" ou "page"
analysis_mode = "plan" analysis_mode = "page"
if __name__ == "__main__": if __name__ == "__main__":
# Configuration basée sur le mode # Configuration basée sur le mode
@ -52,8 +52,12 @@ if __name__ == "__main__":
# Détection et classification des objets # Détection et classification des objets
print("Détection et classification des objets...") print("Détection et classification des objets...")
try: try:
class_counts, detected_objects = pipeline.detect_and_classify_objects() class_counts, detected_objects, total_objects, ignored_objects, identified_objects = pipeline.detect_and_classify_objects()
print("Classes détectées :", class_counts) print(f"Classes détectées : {class_counts}")
print("Résumé des objets :")
print(f"- Objets totaux : {total_objects}")
print(f"- Objets identifiés : {identified_objects}")
print(f"- Objets ignorés : {ignored_objects}")
except Exception as e: except Exception as e:
print(f"Erreur lors de la détection/classification : {e}") print(f"Erreur lors de la détection/classification : {e}")
exit(1) exit(1)

View file

@ -64,7 +64,6 @@ class BayesianClassifier:
features = np.array(features) features = np.array(features)
if features.size == 0: if features.size == 0:
print("No features extracted.")
return np.array([]) return np.array([])
# Normalize features # Normalize features
@ -140,7 +139,6 @@ class BayesianClassifier:
try: try:
features = self.extract_features(image) features = self.extract_features(image)
if features.size == 0: if features.size == 0:
print("Empty features, skipping prediction.")
return None return None
posteriors = {} posteriors = {}

View file

@ -59,9 +59,15 @@ class ObjectDetectionPipeline:
class_counts = defaultdict(int) class_counts = defaultdict(int)
detected_objects = [] detected_objects = []
total_objects = 0
ignored_objects = 0
identified_objects = 0
for contour in contours: for contour in contours:
total_objects += 1 # Compteur total des objets
if cv2.contourArea(contour) < self.min_contour_area: if cv2.contourArea(contour) < self.min_contour_area:
ignored_objects += 1
continue continue
x, y, w, h = cv2.boundingRect(contour) x, y, w, h = cv2.boundingRect(contour)
@ -69,13 +75,14 @@ class ObjectDetectionPipeline:
predicted_class = self.model.predict(letter_image, threshold=self.threshold) predicted_class = self.model.predict(letter_image, threshold=self.threshold)
if predicted_class is None: if predicted_class is None:
print("Object ignored due to low resemblance.") ignored_objects += 1
continue continue
identified_objects += 1
class_counts[predicted_class] += 1 class_counts[predicted_class] += 1
detected_objects.append((x, y, w, h, predicted_class)) detected_objects.append((x, y, w, h, predicted_class))
return dict(sorted(class_counts.items())), detected_objects return dict(sorted(class_counts.items())), detected_objects, total_objects, ignored_objects, identified_objects
def save_results(self, class_counts, detected_objects): def save_results(self, class_counts, detected_objects):
binary_output_path = os.path.join(self.output_dir, "binary_image.jpg") binary_output_path = os.path.join(self.output_dir, "binary_image.jpg")