-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp~
156 lines (127 loc) · 3.38 KB
/
main.cpp~
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "opencv2/core/core.hpp"
#include <opencv/highgui.h>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv/cv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <ctype.h>
#include <math.h>
#include <ctime>
using namespace std;
using namespace cv;
class neuron
{
public:
float sinapsis[50][50];
float value = 0;
neuron()
{
for(int x = 0; x < 50; x++)
{
for(int y = 0; y < 50; y++)
{
sinapsis[x][y] = 1;
}
}
}
};
int main()
{
cout << "Started" << endl;
neuron* pixels[50][50];
neuron* saidas[10];
for(int x = 0; x < 50; x++)
{
for(int y = 0; y < 50; y++)
{
pixels[x][y] = new neuron();
}
}
for(int x = 0; x < 10; x++)
{
saidas[x] = new neuron();
}
cout << pixels[1][1]->sinapsis[1][1] << endl;
cv::Mat images[50];
char alph[5] = { 'a', 'b', 'c','d','e'};
int pos = 0;
for(int o = 0; o < 50; o++)
{
images[o] = cv::imread("numbers/"+std::to_string(o%10)+"_"+alph[pos%5]+".png", CV_LOAD_IMAGE_GRAYSCALE);
if(o%10 == 9) pos++;
}
int cicle = 0;
pos = 0;
int teachFor = 100;
while(true)
{
cicle++;
for(int out = 0; out < 10; out++)
{
saidas[out]->value = 0;
}
int imgN = (cicle % 50);
Mat image = images[imgN];
cout << "image: " + std::to_string(cicle%10)+"_"+alph[pos%5] << endl;
if(cicle%10 == 9) pos++;
imgN = (imgN %10);
for(int out = 0; out < 10; out++)
{
for(int x = 0; x < 50; x++)
{
for(int y = 0; y < 50; y++)
{
uint pix = image.at<uchar>(x,y);
if(pix < 50)
{
saidas[out]->value += saidas[out]->sinapsis[x][y];
}
}
}
}
for(int out = 0; out < 10; out++)
{
cout << out << ": " + std::to_string(saidas[out]->value) << endl;
}
int gueesed = -1;
int maxd = 0;
for(int out = 0; out < 10; out++)
{
if(saidas[out]->value >= maxd)
{
gueesed = out;
maxd = saidas[out]->value;
}
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(30);
cout << "I think it is: " << gueesed << " - The correct number is? " << endl;
string img;
if(cicle >= teachFor)
cin >> img;
else
img = std::to_string(imgN);
int correct = atoi(img.c_str());
//cout << "correct: " << correct << imgN<< endl;
if(correct != gueesed)
{
//cout << "incorrect" << endl;
for(int x = 0; x < 50; x++)
{
for(int y = 0; y < 50; y++)
{
uint pix = image.at<uchar>(x,y);
if(pix < 50)
{
saidas[correct]->sinapsis[x][y] += 1;
}
}
}
}
}
return 0;
}