mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2025-12-21 01:15:52 +00:00
added method to get vector of FeatureVector | added method to get color percentage per raster
This commit is contained in:
@@ -7,4 +7,3 @@ class Concept(Enum):
|
||||
STOP = auto()
|
||||
RECHTS_ABBIEGEN = auto()
|
||||
LINKS_ABBIEGEN = auto()
|
||||
# TODO: add remaining signs
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import cv2 as cv
|
||||
import numpy as np
|
||||
|
||||
from image_processing import raster_image
|
||||
|
||||
blue_lower_hsv = np.array([90, 75, 75])
|
||||
blue_upper_hsv = np.array([130, 255, 255])
|
||||
|
||||
@@ -54,3 +56,14 @@ def get_color_percentage(image: cv.Mat) -> dict:
|
||||
"none": none_percentage
|
||||
}
|
||||
|
||||
def get_raster_color_percentage(image: cv.Mat, rows: int, cols: int) -> list[list[dict]]:
|
||||
rasters2d = raster_image(image, cols, rows)
|
||||
ret = []
|
||||
for raster1d in rasters2d:
|
||||
new = []
|
||||
for raster in raster1d:
|
||||
color_percentage = get_color_percentage(raster)
|
||||
new.append(color_percentage)
|
||||
ret.append(new)
|
||||
return ret
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Any, Self
|
||||
import numpy as np
|
||||
import os
|
||||
import pickle
|
||||
|
||||
@@ -13,10 +14,50 @@ class FeatureVector:
|
||||
self.concept: Concept = concept
|
||||
|
||||
|
||||
def _get_values_of_feature(self, feature: Feature) -> list[int]:
|
||||
try:
|
||||
feature_data = self.features[feature]
|
||||
except KeyError:
|
||||
print("missing key: ", feature)
|
||||
return [-1]
|
||||
|
||||
ret = []
|
||||
if feature == Feature.OVERALL_COLOR_PERCENTAGE:
|
||||
feature_data: dict
|
||||
for val in feature_data.values():
|
||||
ret.append(val)
|
||||
print(ret)
|
||||
return ret
|
||||
|
||||
elif feature == Feature.RASTER_COLOR_PERCENTAGE:
|
||||
feature_data: list[list[dict]]
|
||||
|
||||
for feature_data1d in feature_data:
|
||||
for data in feature_data1d:
|
||||
for val in data.values():
|
||||
ret.append(val)
|
||||
print(ret)
|
||||
return ret
|
||||
|
||||
elif feature == Feature.CORNERS:
|
||||
#feature_data: int #?
|
||||
return [-1]
|
||||
elif feature == Feature.EDGES:
|
||||
#feature_data: int #?
|
||||
return [-1]
|
||||
|
||||
|
||||
def add_feature(self, key: Feature, value: Any) -> None:
|
||||
self.features.update({key: value})
|
||||
|
||||
|
||||
def get_vector(self) -> list:
|
||||
ret = []
|
||||
for feature in Feature:
|
||||
ret = ret + self._get_values_of_feature(feature)
|
||||
return ret
|
||||
|
||||
|
||||
def get_concept(self) -> Concept:
|
||||
return self.concept
|
||||
|
||||
@@ -43,4 +84,3 @@ class FeatureVector:
|
||||
self: FeatureVector = pickle.load(read)
|
||||
return self
|
||||
|
||||
|
||||
|
||||
@@ -115,16 +115,13 @@ def remove_background(image: cv.Mat, lower_rgb: np.ndarray, upper_rgb: np.ndarra
|
||||
|
||||
def raster_image(image: cv.Mat, num_cols: int = 4, num_rows: int = 4) -> list[list[cv.Mat]]:
|
||||
width, height = image.shape[:2]
|
||||
print("w", width, " h", height)
|
||||
rasters = [[0 for x in range(num_rows)] for y in range(num_cols)]
|
||||
print(rasters)
|
||||
for y in range(num_cols):
|
||||
for x in range(num_rows):
|
||||
x1 = int(x * (width/num_rows))
|
||||
y1 = int(y * (height/num_cols))
|
||||
x2 = int((x+1) * (width/num_rows))
|
||||
y2 = int((y+1) * (height/num_cols))
|
||||
print(" x1", x1, " y1", y1, " x2", x2, " y2", y2)
|
||||
|
||||
rasters[x][y] = image[x1:x2, y1:y2]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user