SIFT struggles

This commit is contained in:
Tom Selier 2023-09-20 17:13:58 +02:00
parent e5029e6929
commit 8d52b96268
3 changed files with 11 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

View File

@ -2,23 +2,30 @@ import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
import math
# references:
# https://docs.opencv.org/4.x/da/df5/tutorial_py_sift_intro.html
def magnitude(vector):
return math.sqrt(sum(pow(element, 2) for element in vector))
path = os.path.join(os.getcwd(), './res/trees/accasia_sq1_original.png')
sift = cv2.SIFT.create(enable_precise_upscale=True)
results = np.zeros(0)
mag = np.zeros(0)
labels = []
for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
directory = os.path.join(os.getcwd(), "./res/trees/")
path = os.path.join(directory, filename)
img = cv2.imread(path ,1)
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
kp = sift.detect(gray, None)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
kp = sift.detect(gray, None) # deze bad
(kp, des)= sift.compute(gray, kp)
img = cv2.drawKeypoints(
gray,
kp,
@ -26,10 +33,10 @@ for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
results = np.append(results, len(kp))
labels.append(filename.split('_', 1)[0])
cv2.imshow(filename,img)
break
# cv2.imshow(filename,img)
plt.bar(labels, results)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()