mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2025-12-21 01:15:52 +00:00
created feature vectors
This commit is contained in:
@@ -7,8 +7,9 @@ from feature_vector import FeatureVector
|
||||
from concept import Concept
|
||||
from feature import Feature
|
||||
|
||||
img_path = "/Users/denysseredenko/StreetsignRecognition/data"
|
||||
vector_path = "/Users/denysseredenko/StreetsignRecognition/vector"
|
||||
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"))
|
||||
|
||||
def get_concept(path) -> Concept:
|
||||
if "fahrtrichtung_links" in path:
|
||||
@@ -27,6 +28,11 @@ def get_concept(path) -> Concept:
|
||||
return Concept.UNKNOWN
|
||||
|
||||
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"])
|
||||
|
||||
# go to every file in img_path
|
||||
for dirpath, dnames, fnames in os.walk(img_path):
|
||||
save_path = os.path.join(dirpath.replace(img_path, vector_path))
|
||||
@@ -37,7 +43,11 @@ if __name__ == "__main__":
|
||||
|
||||
for fname in fnames:
|
||||
image_path = os.path.join(dirpath, fname)
|
||||
print(image_path)
|
||||
|
||||
# only create vectors of images in directory 0 (normal brightness)
|
||||
if not "0\\3500" in image_path:
|
||||
continue
|
||||
|
||||
try:
|
||||
# prepare image
|
||||
image = cv.imread(image_path)
|
||||
@@ -66,6 +76,9 @@ if __name__ == "__main__":
|
||||
vec.add_feature(Feature.OVERALL_COLOR_PERCENTAGE, color_percentage_overall)
|
||||
vec.add_feature(Feature.RASTER_COLOR_PERCENTAGE, color_percentage_rasters)
|
||||
|
||||
print(vec.get_vector())
|
||||
vec_path = os.path.join(save_path, fname.split('.')[0])
|
||||
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()])
|
||||
|
||||
vec_path = os.path.join(save_path, fname.replace(".jpg", ".pkl"))
|
||||
vec.save(vec_path)
|
||||
@@ -78,7 +78,7 @@ def get_corners(gray_image: cv.Mat):
|
||||
min_distance = 1
|
||||
corners = cv.goodFeaturesToTrack(cv.blur(gray_image, (5,5)), maxCorners=max_corners, qualityLevel=quality_level, minDistance=min_distance)
|
||||
if corners is not None:
|
||||
corners = np.int0(corners)
|
||||
corners = np.intp(corners) # int0 not working for me :(
|
||||
return len(corners)
|
||||
else:
|
||||
return 0
|
||||
|
||||
1735
src/feature_vectors.csv
Normal file
1735
src/feature_vectors.csv
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user