From 58a802d3227fa963dfdd3ddfbd5aaa0b74d6e426 Mon Sep 17 00:00:00 2001
From: AndersLan <andeslan@stud.ntnu.no>
Date: Wed, 9 Jun 2021 15:44:24 +0200
Subject: [PATCH] added improved code and removen a print

---
 algorithm/brute_force_matching.py | 13 +++++++------
 algorithm/imageprocessing.py      |  2 +-
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/algorithm/brute_force_matching.py b/algorithm/brute_force_matching.py
index 2ebaa94..c69d20a 100644
--- a/algorithm/brute_force_matching.py
+++ b/algorithm/brute_force_matching.py
@@ -5,12 +5,10 @@ import glob
 
 min_good_match = 15
 match_dist = 0.75
-def match_single_image(input_image, match_image):
-    bf = cv2.BFMatcher()
-    input_salamander = create_salamander_image(input_image)
-    match_salamander = create_salamander_image(match_image)
 
-    match = bf.knnMatch(input_salamander.descriptors, match_salamander.descriptors, k=2)
+
+def match_single_image(input_salamander, match_salamander):
+    match = cv2.BFMatcher().knnMatch(input_salamander.descriptors, match_salamander.descriptors, k=2)
 
     goodmatch = []
     for m, n in match:
@@ -20,15 +18,18 @@ def match_single_image(input_image, match_image):
         return True, len(goodmatch)
     return False, 0
 
+
 def match_file_structure(input_image: str, match_directory: str):
     best_match = -1
     match_count = 0
 
+    # check if input path is valid:
     if os.path.isfile(input_image):
+        input_salamander = create_salamander_image(input_image)
         for folder in os.listdir(match_directory):
             name_list = glob.glob(os.path.join(match_directory, folder, "*_str.*"))
             for filename in name_list:
-                res, num_matches = match_single_image(input_image, filename)
+                res, num_matches = match_single_image(input_salamander, create_salamander_image(filename))
                 if res and num_matches > match_count:
                     match_count = num_matches
                     best_match = int(folder)
diff --git a/algorithm/imageprocessing.py b/algorithm/imageprocessing.py
index 7d786ac..522bd3c 100644
--- a/algorithm/imageprocessing.py
+++ b/algorithm/imageprocessing.py
@@ -9,7 +9,7 @@ import algorithm.dsift as dsift
 import algorithm.segmentation as segmentation
 
 def create_salamander_image(filename: str):
-	print("Processing image " + filename)
+	#print("Processing image " + filename)
 	salamander_image = SalamanderImage(filename)
 	
 	salamander_image.filename = filename
-- 
GitLab