Amélioration résultat console
This commit is contained in:
parent
922b9acf18
commit
6da377d7c5
3 changed files with 16 additions and 7 deletions
10
main.py
10
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)
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Add table
Reference in a new issue