created feature vector of all images

This commit is contained in:
Lukas K
2024-11-25 15:06:05 +01:00
parent 5eea061dc5
commit 1cca9bfe4c
2 changed files with 8679 additions and 1740 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
import os
import csv
import cv2 as cv
import re
from util.featue_extraction import get_color_percentage, get_raster_color_percentage, get_edges, get_corners, get_contours
from classes.feature_vector import FeatureVector
@@ -9,7 +10,7 @@ from classes.feature import Feature
img_path = os.path.abspath(os.path.join(__file__, "..", "..", "data", "processed"))
vector_path = os.path.abspath(os.path.join(__file__, "..", "..", "data", "vectors"))
csv_path = os.path.abspath(os.path.join(__file__, "..", "feature_vectors.csv"))
csv_path = os.path.abspath(os.path.join(__file__, "..", "all_feature_vectors.csv"))
def get_concept(path) -> Concept:
if "fahrtrichtung_links" in path:
@@ -31,7 +32,7 @@ if __name__ == "__main__":
# create csv file and insert headers
with open(csv_path, "w") as csv_file:
csv_writer = csv.writer(csv_file, delimiter=";")
csv_writer.writerow(["filename", "concept", "vector"])
csv_writer.writerow(["brightness","filename", "concept", "vector"])
# go to every file in img_path
for dirpath, dnames, fnames in os.walk(img_path):
@@ -45,8 +46,8 @@ if __name__ == "__main__":
image_path = os.path.join(dirpath, fname)
# only create vectors of images in directory 0 (normal brightness)
if not "0\\3500" in image_path:
continue
# if not "0\\3500" in image_path:
# continue
try:
# prepare image
@@ -76,9 +77,11 @@ if __name__ == "__main__":
vec.add_feature(Feature.OVERALL_COLOR_PERCENTAGE, color_percentage_overall)
vec.add_feature(Feature.RASTER_COLOR_PERCENTAGE, color_percentage_rasters)
brightness = re.search(r'(-2|-1|0|\+1|\+2)', image_path)[1]
with open(csv_path, "a") as csv_file:
csv_writer = csv.writer(csv_file, delimiter=";", lineterminator="\n")
csv_writer.writerow([fname, concept, vec.get_vector()])
csv_writer.writerow([brightness, fname, concept, vec.get_vector()])
vec_path = os.path.join(save_path, fname.replace(".jpg", ".pkl"))
vec.save(vec_path)