From 6da377d7c56bd79b987bd861e9f4d4fe57fb9573 Mon Sep 17 00:00:00 2001 From: "yanis.bouarfa" Date: Tue, 7 Jan 2025 23:49:18 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20r=C3=A9sultat=20console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 10 +++++++--- src/classifiers/bayesian.py | 2 -- src/pipeline.py | 11 +++++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index f31a53f..11af68a 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from src.pipeline import ObjectDetectionPipeline from src.classifiers.bayesian import BayesianClassifier # Définissez le mode d'analyse ici : "plan" ou "page" -analysis_mode = "plan" +analysis_mode = "page" if __name__ == "__main__": # Configuration basée sur le mode @@ -52,8 +52,12 @@ if __name__ == "__main__": # Détection et classification des objets print("Détection et classification des objets...") try: - class_counts, detected_objects = pipeline.detect_and_classify_objects() - print("Classes détectées :", class_counts) + class_counts, detected_objects, total_objects, ignored_objects, identified_objects = pipeline.detect_and_classify_objects() + 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: print(f"Erreur lors de la détection/classification : {e}") exit(1) diff --git a/src/classifiers/bayesian.py b/src/classifiers/bayesian.py index 8b964af..c9c2461 100644 --- a/src/classifiers/bayesian.py +++ b/src/classifiers/bayesian.py @@ -64,7 +64,6 @@ class BayesianClassifier: features = np.array(features) if features.size == 0: - print("No features extracted.") return np.array([]) # Normalize features @@ -140,7 +139,6 @@ class BayesianClassifier: try: features = self.extract_features(image) if features.size == 0: - print("Empty features, skipping prediction.") return None posteriors = {} diff --git a/src/pipeline.py b/src/pipeline.py index aa07c31..3e32bb3 100644 --- a/src/pipeline.py +++ b/src/pipeline.py @@ -59,9 +59,15 @@ class ObjectDetectionPipeline: class_counts = defaultdict(int) detected_objects = [] + total_objects = 0 + ignored_objects = 0 + identified_objects = 0 for contour in contours: + total_objects += 1 # Compteur total des objets + if cv2.contourArea(contour) < self.min_contour_area: + ignored_objects += 1 continue x, y, w, h = cv2.boundingRect(contour) @@ -69,13 +75,14 @@ class ObjectDetectionPipeline: predicted_class = self.model.predict(letter_image, threshold=self.threshold) if predicted_class is None: - print("Object ignored due to low resemblance.") + ignored_objects += 1 continue + identified_objects += 1 class_counts[predicted_class] += 1 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): binary_output_path = os.path.join(self.output_dir, "binary_image.jpg")