|
|
| |
/*
* Najprostszy program OCR
* Copyright (C) 2000 Janusz Gregorczyk
* jgregor@kki.net.pl
*/
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
#include "
NNlib.h"
/* ====================================================== */
#define MAX(x, y) ((x) > (y) ? (x) : (y))
const double epsilon = 0.01;
int rndInt(int z) { return rand() % z; }
const int nChars = 10; // liczba wzorców
const int charWidth = 5, charHeight = 7; // wymiary znaków
typedef double CHARSET[nChars][charWidth * charHeight];
CHARSET charData, charInput;
double charOutput[nChars][nChars];
int max(int n, const double *x) {
int j = 0;
for (int i = 1; i < n; i++)
if (x[j] < x[i]) { j = i; }
return j;
}
void loadCharset(const char *fname, CHARSET charset) {
string s;
ifstream in(fname, ios::in | ios::nocreate);
cout << "Wczytuje " << fname << "..." << endl;
for (int n = 0; n < nChars; n++) {
for (int j = 0; j < charHeight; j++) {
getline(in, s);
for (unsigned int i = 0; i < charWidth; i++) {
charset[n][j * charWidth + i] =
(i >= s.length()) || (s[i] != 'O') ? -1.0 : 1.0;
}
}
}
}
int main() {
cout << "Najprostszy OCR" << endl;
cout << "Janusz Gregorczyk`2000" << endl << endl;
double netOutput[nChars];
double error;
loadCharset("pattern.dat", charData);
loadCharset("test.dat", charInput);
for (int i = 0; i < nChars; i++)
for (int j = 0; j < nChars; j++)
charOutput[i][j] = (i == j) ? 1.0 : 0.0;
NeuralNetwork *OCRNN =
new NeuralNetwork(charWidth * charHeight);
OCRNN->addLayer(10);
OCRNN->addLayer(nChars);
OCRNN->setEta(0.25); OCRNN->setAlpha(0.0);
cout << "Trwa uczenie..." << endl;
cout << "[....................]\r[";
OCRNN->startLearning();
int progress = 0;
do {
error = 0.0;
for (int j = 0; j < nChars; j++) {
OCRNN->setInput(charData[j]);
OCRNN->setTarget(charOutput[j]);
OCRNN->propagate();
error = MAX(error, OCRNN->getError());
}
error = MAX(error, epsilon);
while ((epsilon / error * 20.0) > progress) {
cout << "x" << flush; progress++;
}
} while (error > epsilon);
cout << endl << endl;
cout << "Pytanie sieci..." << endl;
OCRNN->stopLearning();
cout << "Wejscie: Wyjscie: Poprawnie?: Blad:" << endl;
for (int j = 0; j < 2; j++) {
for (int i = 0; i < nChars; i++) {
OCRNN->setInput(j ? charInput[i] : charData[i]);
OCRNN->setTarget(charOutput[i]);
OCRNN->propagate();
OCRNN->getOutput(netOutput);
int guess = max(nChars, netOutput);
cout << setw(7) << (j ? '~' : ' ') << i;
cout << setw(8) << guess;
cout << setw(8) << (guess == i ? "tak" : "nie");
cout.setf(ios::fixed);
cout << setprecision(3) << setw(8) << OCRNN->getError();
cout << endl;
}
}
return 0;
}
|
|
 |
| Proponujemy |
|
|
"Tworzenie folderów na woluminach" to już siódmy wykład w cyklu Akademia PCkuriera, który jest poświęcony sztuce administrowania systemem Novell NetWare. Przypominamy, że kurs ten ma pomóc zainteresowanym czytelnikom w samodzielnym przygotowaniu do egzaminu na certyfikat CNA. Częścią kursu jest witryna, zawierająca dodatkowe informacje, materiały szkoleniowe i pytania kontrolne.
|
|
|
 |
|
|
 |
|
|
 |
|