Skip to content
Snippets Groups Projects
Commit 7c9d8a62 authored by AndersLan's avatar AndersLan
Browse files

added improved matching

parent c6f352a7
No related branches found
No related tags found
1 merge request!45Resolve "Add better brute force matching"
...@@ -5,7 +5,7 @@ import glob ...@@ -5,7 +5,7 @@ import glob
min_good_match = 15 min_good_match = 15
match_dist = 0.75 match_dist = 0.75
def match_single_image(input_image, match_image) -> bool: def match_single_image(input_image, match_image):
bf = cv2.BFMatcher() bf = cv2.BFMatcher()
input_salamander = create_salamander_image(input_image) input_salamander = create_salamander_image(input_image)
match_salamander = create_salamander_image(match_image) match_salamander = create_salamander_image(match_image)
...@@ -17,18 +17,21 @@ def match_single_image(input_image, match_image) -> bool: ...@@ -17,18 +17,21 @@ def match_single_image(input_image, match_image) -> bool:
if m.distance < match_dist * n.distance: if m.distance < match_dist * n.distance:
goodmatch.append([m]) goodmatch.append([m])
if len(goodmatch) > min_good_match: if len(goodmatch) > min_good_match:
return True return True, len(goodmatch)
return False return False, 0
def match_file_structure(input_image: str, match_directory: str):
best_match = -1
match_count = 0
def match_file_structure(input_image: str, match_directory: str) -> int:
# check if input path is valid:
if os.path.isfile(input_image): if os.path.isfile(input_image):
for folder in os.listdir(match_directory): for folder in os.listdir(match_directory):
name_list = glob.glob(os.path.join(match_directory, folder, "*_str.*")) name_list = glob.glob(os.path.join(match_directory, folder, "*_str.*"))
for filename in name_list: for filename in name_list:
res = match_single_image(input_image, filename) res, num_matches = match_single_image(input_image, filename)
if res: if res and num_matches > match_count:
return int(folder) match_count = num_matches
return -1 best_match = int(folder)
return best_match
else: else:
return None return None
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment