From 05037b0731ed874772c9566ab19a79a8b6017f66 Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Fri, 29 Sep 2023 21:52:15 +0200 Subject: [PATCH] cleanup --- src/experiments/algorithms/sift_v2.py | 69 --------------------------- src/experiments/algorithms/sift_v3.py | 17 +------ 2 files changed, 1 insertion(+), 85 deletions(-) delete mode 100644 src/experiments/algorithms/sift_v2.py diff --git a/src/experiments/algorithms/sift_v2.py b/src/experiments/algorithms/sift_v2.py deleted file mode 100644 index ce6c713..0000000 --- a/src/experiments/algorithms/sift_v2.py +++ /dev/null @@ -1,69 +0,0 @@ -import numpy as np -import cv2 -import os -import matplotlib.pyplot as plt -import math - -avg_magnitudes = np.zeros(10) -max_magnitudes = np.zeros(10) -avg_angle = np.zeros(10) -counts = np.zeros(10) -i = 0 - -for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")): - ## Load an image ## - directory = os.path.join(os.getcwd(), "./res/trees/") - path = os.path.join(directory, filename) - img = cv2.imread(path, 0) - - ## Detect Keypoints ## - sift = cv2.SIFT.create(enable_precise_upscale=True) - kp = sift.detect(img, None) - img = cv2.drawKeypoints( - img, - kp, - img, - flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) - - ## Average and Max size ## - magnitudes = [keypoint.size for keypoint in kp] - max_magnitudes[i] = np.amax(magnitudes) - avg_magnitudes[i] = np.sum(magnitudes)/len(kp) - - ## Number of keypoints ## - counts[i] = len(kp) - - ## Average angle ## - angle_radians = [math.radians(keypoint.angle) for keypoint in kp] - sum_sin = sum(math.sin(angle) for angle in angle_radians) - sum_cos = sum(math.cos(angle) for angle in angle_radians) - avg_angle_rad = math.atan2(sum_sin, sum_cos) - avg_angle[i] = math.degrees(avg_angle_rad) % 360 - - i += 1 - # break - # cv2.imshow("output", img) - # cv2.waitKey(0) - - -plt.scatter(counts, avg_magnitudes) -plt.title("Hoeveelheid keypoints vs gemiddelde magnitude") -plt.grid() -plt.show() - -plt.scatter(counts, max_magnitudes) -plt.title("Hoeveelheid keypoints vs maximale magnitude") -plt.grid() -plt.show() - -plt.scatter(avg_magnitudes, max_magnitudes) -plt.title("gemiddelde magnitude vs maximale magnitude") -plt.grid() -plt.show() - -plt.scatter(counts, avg_angle) -plt.title("Hoeveelheid keypoints vs gemiddelde hoek") -plt.grid() -plt.show() - -cv2.destroyAllWindows() diff --git a/src/experiments/algorithms/sift_v3.py b/src/experiments/algorithms/sift_v3.py index f6ae40f..af922eb 100644 --- a/src/experiments/algorithms/sift_v3.py +++ b/src/experiments/algorithms/sift_v3.py @@ -78,7 +78,7 @@ for folder in os.listdir(DATASET_PATH): print("Done!") -## Pandas ## +## CSV ## with open(CSV_PATH + "sift.csv" , 'w', newline='') as file: for i in range(len(labels)): file.write(labels[i] + '\n') @@ -91,21 +91,6 @@ with open(CSV_PATH + "sift.csv" , 'w', newline='') as file: file.write(str(max_responses[i][j]) + ',') file.write(str(counts[i][j]) + '\n') -## CSV ## -# with open(CSV_PATH + "data.csv" , 'w', newline='') as file: - # writer = csv.writer(file, delimiter=',') - - # for i in range(len(tot_magnitudes)): - # writer.writerow(tot_magnitudes[i]) - # writer.writerow(avg_magnitudes[i]) - # writer.writerow(max_magnitudes[i]) - # writer.writerow(counts[i]) - # writer.writerow('') - - # writer.writerows(max_magnitudes) - # writer.writerows(avg_magnitudes) - # writer.writerows(counts) - ## Plots ## # fig, ax = plt.subplots() # for i in range(DATASET_FOLDERS_LEN):