Merge branch 'main' of https://arnweb.nl/gitea/arne/EV5_Beeldherk_Bomen
This commit is contained in:
commit
27312ae6df
28
src/helpers/algorithms/colourspace.py
Normal file
28
src/helpers/algorithms/colourspace.py
Normal file
@ -0,0 +1,28 @@
|
||||
import cv2
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
DATASET_PATH = "C:\\Users\\tomse\\Documents\\Dataset\\"
|
||||
|
||||
full_img = cv2.imread(DATASET_PATH + "alder\\1.jpg", 1)
|
||||
bgr_img = cv2.resize(full_img, (0, 0), fx=0.2, fy=0.2)
|
||||
hsv_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)
|
||||
|
||||
cv2.imshow('BGR',bgr_img)
|
||||
cv2.imshow('HSV',hsv_img)
|
||||
cv2.imshow('HSV - H',hsv_img[:, :, 0])
|
||||
cv2.imshow('HSV - S',hsv_img[:, :, 1])
|
||||
cv2.imshow('HSV - V',hsv_img[:, :, 2])
|
||||
|
||||
|
||||
hist = cv2.calcHist([hsv_img], [0], None, [256], [0,256])
|
||||
plt.plot(hist, label='H')
|
||||
hist = cv2.calcHist([hsv_img], [1], None, [256], [0,256])
|
||||
plt.plot(hist, label='S')
|
||||
hist = cv2.calcHist([hsv_img], [2], None, [256], [0,256])
|
||||
plt.plot(hist, label='V')
|
||||
plt.grid()
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
61
src/helpers/algorithms/sift_v3.py
Normal file
61
src/helpers/algorithms/sift_v3.py
Normal file
@ -0,0 +1,61 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
DATASET_PATH = "C:\\Users\\tomse\\Documents\\Dataset\\"
|
||||
DATASET_FOLDERS_LEN = len(os.listdir(DATASET_PATH))
|
||||
EARLY_BREAK = 3
|
||||
|
||||
sift = cv2.SIFT.create(enable_precise_upscale=True)
|
||||
|
||||
## Create 2D lists ##
|
||||
max_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
avg_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
counts = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
|
||||
## Create other variables ##
|
||||
labels = ['' for x in range(DATASET_FOLDERS_LEN)]
|
||||
i = 0
|
||||
|
||||
for folder in os.listdir(DATASET_PATH):
|
||||
if EARLY_BREAK:
|
||||
print("Step %d/%d processing %s:"%(i+1, EARLY_BREAK, folder))
|
||||
else:
|
||||
print("Step %d/%d processing %s:"%(i+1, DATASET_FOLDERS_LEN, folder))
|
||||
|
||||
for file in os.listdir(DATASET_PATH + folder):
|
||||
## Load an image ##
|
||||
path = DATASET_PATH + folder + "\\" + file
|
||||
full_image = cv2.imread(path, 0)
|
||||
image = cv2.resize(full_image, (0, 0), fx=0.25, fy=0.25)
|
||||
|
||||
## Detect keypoints ##
|
||||
kp = sift.detect(image, None)
|
||||
|
||||
## Average and Max size ##
|
||||
magnitudes = [keypoint.size for keypoint in kp]
|
||||
max_magnitudes[i].append(np.amax(magnitudes))
|
||||
avg_magnitudes[i].append(np.sum(magnitudes)/len(kp))
|
||||
|
||||
## Number of keypoints ##
|
||||
counts[i].append(len(kp))
|
||||
|
||||
## Store labels ##
|
||||
labels[i] = folder
|
||||
|
||||
## Increment folder ##
|
||||
i += 1
|
||||
|
||||
if(i == EARLY_BREAK):
|
||||
break
|
||||
|
||||
print("Done!")
|
||||
|
||||
## Plots ##
|
||||
fig, ax = plt.subplots()
|
||||
for i in range(DATASET_FOLDERS_LEN):
|
||||
ax.scatter(avg_magnitudes[i], max_magnitudes[i],label=labels[i], alpha=0.7)
|
||||
ax.legend()
|
||||
ax.grid(True)
|
||||
plt.show()
|
Loading…
Reference in New Issue
Block a user