Added features to sift
This commit is contained in:
parent
8d52b96268
commit
9267e068cc
Binary file not shown.
@ -25,7 +25,6 @@ for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
|
|||||||
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
||||||
kp = sift.detect(gray, None) # deze bad
|
kp = sift.detect(gray, None) # deze bad
|
||||||
(kp, des)= sift.compute(gray, kp)
|
(kp, des)= sift.compute(gray, kp)
|
||||||
|
|
||||||
img = cv2.drawKeypoints(
|
img = cv2.drawKeypoints(
|
||||||
gray,
|
gray,
|
||||||
kp,
|
kp,
|
||||||
@ -33,8 +32,8 @@ for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
|
|||||||
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
|
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
|
||||||
results = np.append(results, len(kp))
|
results = np.append(results, len(kp))
|
||||||
labels.append(filename.split('_', 1)[0])
|
labels.append(filename.split('_', 1)[0])
|
||||||
break
|
# break
|
||||||
# cv2.imshow(filename,img)
|
cv2.imshow(filename,img)
|
||||||
|
|
||||||
plt.bar(labels, results)
|
plt.bar(labels, results)
|
||||||
plt.show()
|
plt.show()
|
||||||
|
69
src/helpers/algorithms/sift_v2.py
Normal file
69
src/helpers/algorithms/sift_v2.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
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()
|
Loading…
Reference in New Issue
Block a user