-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptchasim.cpp
More file actions
executable file
·87 lines (66 loc) · 1.84 KB
/
Copy pathcaptchasim.cpp
File metadata and controls
executable file
·87 lines (66 loc) · 1.84 KB
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
#include <highgui.h>
#include <cv.h>
#include <ml.h>
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char *argv[]){
if(argc<3){
cout << "Usage: ./" << argv[0] << " < Infile Net > < Test Case 1 >...< Test Case N >" << endl;
exit(-1);
}
CvANN_MLP red;
red.load(argv[1]);
//Matrices
Mat input, src;
for(int i =2; i<argc; i++){
//Se leen las imagenes por argumentos
src = imread(argv[i],CV_LOAD_IMAGE_GRAYSCALE);
//cout << argv[i][6] << argv[i][6]-'A' << endl;
/*Mat out;
out = Mat::zeros(1,26,CV_32FC1);
out.at<float>(argv[i][6]-'A')=1;
output.push_back(out);
cout << out<<endl;*/
if(!src.data){
cout << "Error al leer la imagen" << endl;
continue;
}
//Turns matrix to vector
src = src.reshape(0,1);
//Push it to the input matrix
input.push_back(src);
//cout << src<<endl;
}
//The number of training samples.
int train_sample_count = input.rows;
//Get the number of samples.
printf("Found training file with %d samples...\n", train_sample_count);
//Create the matrices
//Input data samples. Matrix of order (train_sample_count x 2)
Mat trainData;
input.convertTo(trainData,CV_32FC1);
Mat closeenough;
red.predict(trainData, closeenough);
int k=0;
int corr =0;
for(int i=0; i<train_sample_count; i++){
float max=-2;
int m=0;
for(int j=0; j<26; j++){
if(closeenough.at<float>(i,j)>max){
m=j;
max=closeenough.at<float>(i,j);
}
}
printf("%c",m+'A');
if(k+'A'==m+'A')corr++;
if((i+1)%100==0){
printf(" %d\n",corr);
k++;
corr=0;
}
}
}