This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_stage.py
66 lines (52 loc) · 2.06 KB
/
classify_stage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python
import string
import cv2
import numpy
from classes.preprocessing import Preprocessing
from classes.tools import Tools
from classes.database import Database
from classes.histogram import Histogram
from classes.featureExtraction import FeatureExtraction
from classes.pca import PCA
from classes.classify import Classify
tools = Tools()
database = Database()
database.loadDatabase()
def run(singleChar):
# Histogram
histogram2 = Histogram(singleChar)
histogram_merkmale = histogram2.rowWert2wert()
# Pixel Average
pix_av2 = FeatureExtraction(singleChar)
pix_av_merkmale = pix_av2.getpixelaverage()
# PCA
pca2 = PCA()
pca2.testChar(singleChar) # In PCA Klasse laden
pca2.matrix -= numpy.array(database.read('common', 'pca_mean')) # Mean Vector aus Datenbank
pca_merkmale = pca2.pca(
numpy.array(database.read('common',
'pca_eig')[0]))
temp = list()
for j in list(pca_merkmale.T[0]):
temp.append(float(j))
featureVector = [pix_av_merkmale] + histogram_merkmale + temp
classify = Classify()
classify.crispKnn(featureVector, 3)
# print(featureVector)
characterCount = 4
## CLASSIFICATION
featureVectors = database.readFeatureVectors()
for char in featureVectors:
for char_vector_count in featureVectors[char]:
membershipvalue = 0 # Example value
database.add("featureMembership", char + str(char_vector_count),
membershipvalue) # Write to database. Don't forget to save database with database.saveDatabase()
membershipvalue = database.read("featureMembership", char + str(char_vector_count)) # Read back from database.
# Testbild wird hier geladen und auf gleiche Weise durch Preprocessing gejagt
img = cv2.imread('trainingdata/trainingsdata.off/helloworld.png', cv2.IMREAD_GRAYSCALE)
preprocess = Preprocessing(img)
preprocess.binariseImg()
splitted_chars = preprocess.splitChars()
for i in range(len(splitted_chars)):
#tools.writeImage(splitted_chars[i], "out" + str(i) + '.png')
run(splitted_chars[i])