mirror of
https://github.com/3x4byte/StreetsignRecognition.git
synced 2025-12-21 01:15:52 +00:00
project structure | added image processing (cropping, background remove)
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,5 +2,4 @@
|
|||||||
.vsc
|
.vsc
|
||||||
.venv
|
.venv
|
||||||
|
|
||||||
./data/*
|
data
|
||||||
!./data/.gitkeep
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
opencv-python
|
||||||
10
src/concept.py
Normal file
10
src/concept.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from enum import Enum, auto
|
||||||
|
|
||||||
|
class Concept(Enum):
|
||||||
|
UNKNOWN = auto()
|
||||||
|
VORFAHRT_GEWAEHREN = auto()
|
||||||
|
VORFAHRT_STRASSE = auto()
|
||||||
|
STOP = auto()
|
||||||
|
RECHTS_ABBIEGEN = auto()
|
||||||
|
LINKS_ABBIEGEN = auto()
|
||||||
|
# TODO: add remaining signs
|
||||||
8
src/featue_extraction.py
Normal file
8
src/featue_extraction.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
class FeatureExtractor:
|
||||||
|
|
||||||
|
def get_overall_color_percentage():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def get_color_per_raster_percentage():
|
||||||
|
pass
|
||||||
|
|
||||||
27
src/feature_vector.py
Normal file
27
src/feature_vector.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from concept import Concept
|
||||||
|
|
||||||
|
|
||||||
|
class FeatureVector:
|
||||||
|
|
||||||
|
def __init__(self, concept: Concept, features: dict = {}) -> None:
|
||||||
|
self.features: dict = features
|
||||||
|
self.concept: Concept = concept
|
||||||
|
|
||||||
|
|
||||||
|
def add_feature(self, key, value) -> None:
|
||||||
|
self.features.update({key: value})
|
||||||
|
|
||||||
|
|
||||||
|
def get_concept(self) -> Concept:
|
||||||
|
return self.concept
|
||||||
|
|
||||||
|
|
||||||
|
def get_num_features(self) -> int:
|
||||||
|
return len(self.features)
|
||||||
|
|
||||||
|
|
||||||
|
def get_feature_value(self, key) -> Any:
|
||||||
|
return self.features[key]
|
||||||
|
|
||||||
93
src/image_processing.py
Normal file
93
src/image_processing.py
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import cv2 as cv
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def crop(image: cv.Mat) -> cv.Mat:
|
||||||
|
width, height = image.shape[:2]
|
||||||
|
|
||||||
|
x1 = None
|
||||||
|
for x in range(width):
|
||||||
|
for y in range(height):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r < 150 and g < 150 and b < 150):
|
||||||
|
x1 = x
|
||||||
|
break
|
||||||
|
if x1 is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
y1 = None
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r < 150 and g < 150 and b < 150):
|
||||||
|
y1 = y
|
||||||
|
break
|
||||||
|
if y1 is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
x2 = None
|
||||||
|
for x in range(width-1, 0, -1):
|
||||||
|
for y in range(height):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r < 150 and g < 150 and b < 150):
|
||||||
|
x2 = x
|
||||||
|
break
|
||||||
|
if x2 is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
y2 = None
|
||||||
|
for y in range(height-1, 0, -1):
|
||||||
|
for x in range(width):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r < 150 and g < 150 and b < 150):
|
||||||
|
y2 = y
|
||||||
|
break
|
||||||
|
if y2 is not None:
|
||||||
|
break
|
||||||
|
|
||||||
|
return image[x1-2:x2+2, y1-2:y2+2]
|
||||||
|
|
||||||
|
|
||||||
|
def remove_background(image: cv.Mat, lower_rgb: np.ndarray) -> cv.Mat:
|
||||||
|
width, height = image.shape[:2]
|
||||||
|
|
||||||
|
# left to right
|
||||||
|
for x in range(width):
|
||||||
|
for y in range(height):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r >= lower_rgb[0] and g >= lower_rgb[1] and b >= lower_rgb[2]):
|
||||||
|
image[x][y] = [0, 0, 0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
# top to bottom
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r >= lower_rgb[0] and g >= lower_rgb[1] and b >= lower_rgb[2]):
|
||||||
|
image[x][y] = [0, 0, 0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
# right to left
|
||||||
|
for x in range(width):
|
||||||
|
for y in range(height-1, 0, -1):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r >= lower_rgb[0] and g >= lower_rgb[1] and b >= lower_rgb[2]):
|
||||||
|
image[x][y] = [0, 0, 0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
# bottom to top
|
||||||
|
for y in range(height):
|
||||||
|
for x in range(width-1, 0, -1):
|
||||||
|
b, g, r = image[x][y]
|
||||||
|
if(r >= lower_rgb[0] and g >= lower_rgb[1] and b >= lower_rgb[2]):
|
||||||
|
image[x][y] = [0, 0, 0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
def raster_image(image: cv.Mat, num_cols: int = 4, num_rows: int = 4) -> dict[cv.Mat]:
|
||||||
|
pass
|
||||||
17
src/learner.py
Normal file
17
src/learner.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class Learner:
|
||||||
|
# The training method, that changes the internal state of the learner such that
|
||||||
|
# it will classify examples of a similar set (i.e. the testSet better.
|
||||||
|
#
|
||||||
|
# @param trainingSet contains feature vectors and corresponding concepts
|
||||||
|
# to provide experience to learn from
|
||||||
|
|
||||||
|
def learn(trainingSet):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# find the concept of the example from the internal knowledge of the lerner
|
||||||
|
# this method must not consider example.getConcept() at all!!
|
||||||
|
#
|
||||||
|
# @param example: is a feature vector
|
||||||
|
# @return the concept of the examplke as learned by this before
|
||||||
|
def classify(example):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user