00001
00020 #include "mfcpch.h"
00021 #include "errcode.h"
00022
00023 #include "globals.h"
00024
00025 #define OUTPUT_NODES 94
00026
00027 const ERRCODE NETINIT = "NN init error";
00028
00029
00030
00031
00032
00033 void init_net() {
00034 #ifdef ASPIRIN_INCLUDED
00035 char wts_filename[256];
00036
00037 if (nmatch_init_network () != 0) {
00038 NETINIT.error ("Init_net", EXIT, "Errcode %s", nmatch_error_string ());
00039 }
00040 strcpy(wts_filename, demodir);
00041 strcat (wts_filename, "tessdata/netwts");
00042
00043 if (nmatch_load_network (wts_filename) != 0) {
00044 NETINIT.error ("Init_net", EXIT, "Weights failed, Errcode %s",
00045 nmatch_error_string ());
00046 }
00047 #endif
00048 }
00049
00050
00052 void callnet(
00053 float *input_vector,
00054 char *top,
00055 float *top_score,
00056 char *next,
00057 float *next_score) {
00058 #ifdef ASPIRIN_INCLUDED
00059 float *output_vector;
00060 int i;
00061 int max_out_i = 0;
00062 int next_max_out_i = 0;
00063 float max_out = -9;
00064 float next_max_out = -9;
00065
00066 nmatch_set_input(input_vector);
00067 nmatch_propagate_forward();
00068 output_vector = nmatch_get_output ();
00069
00070
00071 for (i = 0; i < OUTPUT_NODES; i++) {
00072 if (output_vector[i] > max_out) {
00073 next_max_out = max_out;
00074 max_out = output_vector[i];
00075 next_max_out_i = max_out_i;
00076 max_out_i = i;
00077 }
00078 else {
00079 if (output_vector[i] > next_max_out) {
00080 next_max_out = output_vector[i];
00081 next_max_out_i = i;
00082 }
00083 }
00084 }
00085 *top = max_out_i + '!';
00086 *next = next_max_out_i + '!';
00087 *top_score = max_out;
00088 *next_score = next_max_out;
00089 #endif
00090 }
00091
00092