This commit is contained in:
Tom Selier 2023-09-29 21:52:15 +02:00
parent 9d5b1b8a40
commit 05037b0731
2 changed files with 1 additions and 85 deletions

View File

@ -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()

View File

@ -78,7 +78,7 @@ for folder in os.listdir(DATASET_PATH):
print("Done!") print("Done!")
## Pandas ## ## CSV ##
with open(CSV_PATH + "sift.csv" , 'w', newline='') as file: with open(CSV_PATH + "sift.csv" , 'w', newline='') as file:
for i in range(len(labels)): for i in range(len(labels)):
file.write(labels[i] + '\n') 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(max_responses[i][j]) + ',')
file.write(str(counts[i][j]) + '\n') 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 ## ## Plots ##
# fig, ax = plt.subplots() # fig, ax = plt.subplots()
# for i in range(DATASET_FOLDERS_LEN): # for i in range(DATASET_FOLDERS_LEN):