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 matplotlib.pyplot as plt
import cv2 import cv2
import os import os
import math
# references: # references:
# https://docs.opencv.org/4.x/da/df5/tutorial_py_sift_intro.html # 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') path = os.path.join(os.getcwd(), './res/trees/accasia_sq1_original.png')
sift = cv2.SIFT.create(enable_precise_upscale=True) sift = cv2.SIFT.create(enable_precise_upscale=True)
results = np.zeros(0) results = np.zeros(0)
mag = np.zeros(0)
labels = [] labels = []
for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")): for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
directory = os.path.join(os.getcwd(), "./res/trees/") directory = os.path.join(os.getcwd(), "./res/trees/")
path = os.path.join(directory, filename) path = os.path.join(directory, filename)
img = cv2.imread(path ,1) img = cv2.imread(path ,1)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
kp = sift.detect(gray, None) kp = sift.detect(gray, None) # deze bad
(kp, des)= sift.compute(gray, kp)
img = cv2.drawKeypoints( img = cv2.drawKeypoints(
gray, gray,
kp, 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) 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])
cv2.imshow(filename,img) break
# cv2.imshow(filename,img)
plt.bar(labels, results) plt.bar(labels, results)
plt.show() plt.show()
cv2.waitKey(0) cv2.waitKey(0)
cv2.destroyAllWindows() cv2.destroyAllWindows()