Compare commits
3 Commits
5aba28b120
...
a8c7581fac
Author | SHA1 | Date | |
---|---|---|---|
a8c7581fac | |||
f7a530395d | |||
33b76cce9a |
@ -3,15 +3,19 @@ import cv2
|
|||||||
import os
|
import os
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
DATASET_PATH = "C:\\Users\\tomse\\Documents\\Dataset\\"
|
DATASET_PATH = "C:\\Users\\tomse\\Downloads\\Dataset\\"
|
||||||
DATASET_FOLDERS_LEN = len(os.listdir(DATASET_PATH))
|
DATASET_FOLDERS_LEN = len(os.listdir(DATASET_PATH))
|
||||||
EARLY_BREAK = 3
|
EARLY_BREAK = 0
|
||||||
|
SCALE = 1
|
||||||
|
|
||||||
|
# Plataan, Berk, Accasia
|
||||||
|
|
||||||
sift = cv2.SIFT.create(enable_precise_upscale=True)
|
sift = cv2.SIFT.create(enable_precise_upscale=True)
|
||||||
|
|
||||||
## Create 2D lists ##
|
## Create 2D lists ##
|
||||||
max_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
max_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||||
avg_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
avg_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||||
|
tot_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||||
counts = [[] for x in range(DATASET_FOLDERS_LEN)]
|
counts = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||||
|
|
||||||
## Create other variables ##
|
## Create other variables ##
|
||||||
@ -19,6 +23,9 @@ labels = ['' for x in range(DATASET_FOLDERS_LEN)]
|
|||||||
i = 0
|
i = 0
|
||||||
|
|
||||||
for folder in os.listdir(DATASET_PATH):
|
for folder in os.listdir(DATASET_PATH):
|
||||||
|
if not folder.endswith("_out"):
|
||||||
|
continue
|
||||||
|
|
||||||
if EARLY_BREAK:
|
if EARLY_BREAK:
|
||||||
print("Step %d/%d processing %s:"%(i+1, EARLY_BREAK, folder))
|
print("Step %d/%d processing %s:"%(i+1, EARLY_BREAK, folder))
|
||||||
else:
|
else:
|
||||||
@ -28,18 +35,27 @@ for folder in os.listdir(DATASET_PATH):
|
|||||||
## Load an image ##
|
## Load an image ##
|
||||||
path = DATASET_PATH + folder + "\\" + file
|
path = DATASET_PATH + folder + "\\" + file
|
||||||
full_image = cv2.imread(path, 0)
|
full_image = cv2.imread(path, 0)
|
||||||
image = cv2.resize(full_image, (0, 0), fx=0.25, fy=0.25)
|
image = cv2.resize(full_image, (0, 0), fx=SCALE, fy=SCALE)
|
||||||
|
|
||||||
## Detect keypoints ##
|
## Detect keypoints ##
|
||||||
kp = sift.detect(image, None)
|
kp = sift.detect(image, None)
|
||||||
|
image = cv2.drawKeypoints(
|
||||||
|
image,
|
||||||
|
kp,
|
||||||
|
image,
|
||||||
|
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
|
||||||
|
|
||||||
## Average and Max size ##
|
## Average and Max size ##
|
||||||
magnitudes = [keypoint.size for keypoint in kp]
|
magnitudes = [keypoint.size for keypoint in kp]
|
||||||
|
tot_magnitudes[i].append(np.sum(magnitudes))
|
||||||
max_magnitudes[i].append(np.amax(magnitudes))
|
max_magnitudes[i].append(np.amax(magnitudes))
|
||||||
avg_magnitudes[i].append(np.sum(magnitudes)/len(kp))
|
avg_magnitudes[i].append(np.sum(magnitudes)/len(kp))
|
||||||
|
|
||||||
## Number of keypoints ##
|
## Number of keypoints ##
|
||||||
counts[i].append(len(kp))
|
counts[i].append(len(kp))
|
||||||
|
|
||||||
|
# cv2.imshow("Opencv tech", image)
|
||||||
|
# cv2.waitKey(0)
|
||||||
|
|
||||||
## Store labels ##
|
## Store labels ##
|
||||||
labels[i] = folder
|
labels[i] = folder
|
||||||
@ -54,8 +70,21 @@ print("Done!")
|
|||||||
|
|
||||||
## Plots ##
|
## Plots ##
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
for i in range(DATASET_FOLDERS_LEN):
|
# for i in range(DATASET_FOLDERS_LEN):
|
||||||
ax.scatter(avg_magnitudes[i], max_magnitudes[i],label=labels[i], alpha=0.7)
|
# ax.scatter(tot_magnitudes[i], max_magnitudes[i],label=labels[i], alpha=0.7)
|
||||||
ax.legend()
|
# ax.scatter(avg_magnitudes[0], max_magnitudes[0], label=labels[0], alpha=0.7)
|
||||||
|
# ax.scatter(avg_magnitudes[7], max_magnitudes[7], label=labels[7], alpha=0.7)
|
||||||
|
# ax.set_xlabel("Gemiddelde magnitude")
|
||||||
|
# ax.set_ylabel("Maximale magnitude")
|
||||||
|
# ax.legend()
|
||||||
|
# ax.grid(True)
|
||||||
|
# plt.show()
|
||||||
|
|
||||||
|
ax.scatter(tot_magnitudes[2], max_magnitudes[2], label='Berk', alpha=0.7)
|
||||||
|
ax.scatter(tot_magnitudes[3], max_magnitudes[3], label='Els', alpha=0.7)
|
||||||
|
ax.scatter(tot_magnitudes[7], max_magnitudes[7], label='Plataan', alpha=0.7)
|
||||||
|
ax.set_xlabel("Total magnitude")
|
||||||
|
ax.set_ylabel("Maximal magnitude")
|
||||||
|
ax.legend()
|
||||||
ax.grid(True)
|
ax.grid(True)
|
||||||
plt.show()
|
plt.show()
|
@ -110,6 +110,8 @@ for folder in os.listdir(input_directory):
|
|||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
print("Created folder: " + out_folder)
|
print("Created folder: " + out_folder)
|
||||||
os.mkdir(out_folder)
|
os.mkdir(out_folder)
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
for file in os.listdir(os.path.join(input_directory, folder)):
|
for file in os.listdir(os.path.join(input_directory, folder)):
|
||||||
## Laad plaatjes in kleur ##
|
## Laad plaatjes in kleur ##
|
||||||
@ -139,6 +141,9 @@ for folder in os.listdir(input_directory):
|
|||||||
corners,
|
corners,
|
||||||
ids)
|
ids)
|
||||||
|
|
||||||
|
if VERBOSE:
|
||||||
|
print("IDs detected:\n", ids)
|
||||||
|
|
||||||
if ids is None:
|
if ids is None:
|
||||||
print("Skipping: ", filename)
|
print("Skipping: ", filename)
|
||||||
print("=============================================")
|
print("=============================================")
|
||||||
|
Loading…
Reference in New Issue
Block a user