mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2025-12-21 09:25: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 concept import Concept
|
||||||
from feature import Feature
|
from feature import Feature
|
||||||
|
|
||||||
img_path = "/Users/denysseredenko/StreetsignRecognition/data"
|
img_path = os.path.abspath(os.path.join(__file__, "..", "..", "data", "processed"))
|
||||||
vector_path = "/Users/denysseredenko/StreetsignRecognition/vector"
|
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:
|
def get_concept(path) -> Concept:
|
||||||
if "fahrtrichtung_links" in path:
|
if "fahrtrichtung_links" in path:
|
||||||
@@ -27,6 +28,11 @@ def get_concept(path) -> Concept:
|
|||||||
return Concept.UNKNOWN
|
return Concept.UNKNOWN
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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
|
# go to every file in img_path
|
||||||
for dirpath, dnames, fnames in os.walk(img_path):
|
for dirpath, dnames, fnames in os.walk(img_path):
|
||||||
save_path = os.path.join(dirpath.replace(img_path, vector_path))
|
save_path = os.path.join(dirpath.replace(img_path, vector_path))
|
||||||
@@ -37,7 +43,11 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
image_path = os.path.join(dirpath, fname)
|
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:
|
try:
|
||||||
# prepare image
|
# prepare image
|
||||||
image = cv.imread(image_path)
|
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.OVERALL_COLOR_PERCENTAGE, color_percentage_overall)
|
||||||
vec.add_feature(Feature.RASTER_COLOR_PERCENTAGE, color_percentage_rasters)
|
vec.add_feature(Feature.RASTER_COLOR_PERCENTAGE, color_percentage_rasters)
|
||||||
|
|
||||||
print(vec.get_vector())
|
with open(csv_path, "a") as csv_file:
|
||||||
vec_path = os.path.join(save_path, fname.split('.')[0])
|
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)
|
vec.save(vec_path)
|
||||||
@@ -78,7 +78,7 @@ def get_corners(gray_image: cv.Mat):
|
|||||||
min_distance = 1
|
min_distance = 1
|
||||||
corners = cv.goodFeaturesToTrack(cv.blur(gray_image, (5,5)), maxCorners=max_corners, qualityLevel=quality_level, minDistance=min_distance)
|
corners = cv.goodFeaturesToTrack(cv.blur(gray_image, (5,5)), maxCorners=max_corners, qualityLevel=quality_level, minDistance=min_distance)
|
||||||
if corners is not None:
|
if corners is not None:
|
||||||
corners = np.int0(corners)
|
corners = np.intp(corners) # int0 not working for me :(
|
||||||
return len(corners)
|
return len(corners)
|
||||||
else:
|
else:
|
||||||
return 0
|
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