added some feature detection algorithms

This commit is contained in:
Tom Selier 2023-09-16 16:46:09 +02:00
parent 44a828a880
commit 43c82fb95c
2 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import cv2
import os
import matplotlib.pyplot as plt
import numpy as np
path = os.path.join(os.getcwd(), './res/trees/accasia_sq1_original.png')
orb = cv2.ORB.create(nfeatures=int(10e6))
results = 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 = orb.detect(gray, None)
kp, des = orb.compute(img, kp)
gray = cv2.drawKeypoints(
gray,
kp,
None,
#flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS
)
results = np.append(results, len(kp))
labels.append(filename.split('_', 1)[0])
print(len(des))
cv2.imshow(path, gray)
plt.bar(labels, results)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()

View File

@ -0,0 +1,35 @@
import numpy as np
import matplotlib.pyplot as plt
import cv2
import os
# references:
# https://docs.opencv.org/4.x/da/df5/tutorial_py_sift_intro.html
path = os.path.join(os.getcwd(), './res/trees/accasia_sq1_original.png')
sift = cv2.SIFT.create(enable_precise_upscale=True)
results = 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)
img = cv2.drawKeypoints(
gray,
kp,
img,
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
results = np.append(results, len(kp))
labels.append(filename.split('_', 1)[0])
cv2.imshow(filename,img)
plt.bar(labels, results)
plt.show()
cv2.waitKey(0)
cv2.destroyAllWindows()