|
|
|
@ -121,12 +121,10 @@ public class ANNTrain {
|
|
|
|
|
for (int i = 0; i < Constant.numCharacter; i++) {
|
|
|
|
|
String str = DEFAULT_PATH + "learn/" + Constant.strCharacters[i];
|
|
|
|
|
Vector<String> files = new Vector<String>();
|
|
|
|
|
FileUtil.getFiles(str, files);
|
|
|
|
|
FileUtil.getFiles(str, files); // 文件名不能包含中文
|
|
|
|
|
|
|
|
|
|
int size = (int) files.size();
|
|
|
|
|
for (int j = 0; j < size; j++) {
|
|
|
|
|
Mat img = Imgcodecs.imread(files.get(j), 0);
|
|
|
|
|
// System.err.println(files.get(j)); // 文件名不能包含中文
|
|
|
|
|
for (String filePath : files) {
|
|
|
|
|
Mat img = Imgcodecs.imread(filePath);
|
|
|
|
|
Mat f = features(img, _predictsize);
|
|
|
|
|
samples.push_back(f);
|
|
|
|
|
trainingLabels.add(i); // 每一幅字符图片所对应的字符类别索引下标
|
|
|
|
@ -138,18 +136,14 @@ public class ANNTrain {
|
|
|
|
|
String str = DEFAULT_PATH + "learn/" + Constant.strChinese[i];
|
|
|
|
|
Vector<String> files = new Vector<String>();
|
|
|
|
|
FileUtil.getFiles(str, files);
|
|
|
|
|
|
|
|
|
|
int size = (int) files.size();
|
|
|
|
|
for (int j = 0; j < size; j++) {
|
|
|
|
|
Mat img = Imgcodecs.imread(files.get(j), 0);
|
|
|
|
|
// System.err.println(files.get(j)); // 文件名不能包含中文
|
|
|
|
|
for (String filePath : files) {
|
|
|
|
|
Mat img = Imgcodecs.imread(filePath);
|
|
|
|
|
Mat f = features(img, _predictsize);
|
|
|
|
|
samples.push_back(f);
|
|
|
|
|
trainingLabels.add(i + Constant.numCharacter);
|
|
|
|
|
trainingLabels.add(i + Constant.numCharacter); // 每一幅字符图片所对应的字符类别索引下标
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//440 vhist.length + hhist.length + lowData.cols() * lowData.rows();
|
|
|
|
|
// CV_32FC1 CV_32SC1 CV_32F
|
|
|
|
|
Mat classes = new Mat(trainingLabels.size(), Constant.numAll, CvType.CV_32F);
|
|
|
|
@ -168,7 +162,7 @@ public class ANNTrain {
|
|
|
|
|
layers.put(0, 1, _neurons);
|
|
|
|
|
layers.put(0, 2, classes.cols());
|
|
|
|
|
|
|
|
|
|
System.out.println(layers);
|
|
|
|
|
// System.out.println(layers);
|
|
|
|
|
|
|
|
|
|
ann.setLayerSizes(layers);
|
|
|
|
|
ann.setActivationFunction(ANN_MLP.SIGMOID_SYM, 1, 1);
|
|
|
|
@ -191,6 +185,7 @@ public class ANNTrain {
|
|
|
|
|
Vector<String> files = new Vector<String>();
|
|
|
|
|
FileUtil.getFiles(DEFAULT_PATH + "test/", files);
|
|
|
|
|
|
|
|
|
|
String plate = "";
|
|
|
|
|
for (String string : files) {
|
|
|
|
|
Mat img = Imgcodecs.imread(string, 0);
|
|
|
|
|
Mat f = features(img, Constant.predictSize);
|
|
|
|
@ -199,12 +194,21 @@ public class ANNTrain {
|
|
|
|
|
// 440 predictSize = 20;
|
|
|
|
|
Mat output = new Mat(1, 140, CvType.CV_32F);
|
|
|
|
|
//ann.predict(f, output, 0); // 预测结果
|
|
|
|
|
System.err.println(string + "===>" + (int) ann.predict(f, output, 0));
|
|
|
|
|
|
|
|
|
|
// ann.predict(f, output, 0);
|
|
|
|
|
// System.err.println(string + "===>" + output.get(0, 0)[0]);
|
|
|
|
|
|
|
|
|
|
int index = (int) ann.predict(f, output, 0);
|
|
|
|
|
System.err.println(string + "===>" + index);
|
|
|
|
|
|
|
|
|
|
if (index < Constant.numCharacter) {
|
|
|
|
|
plate += String.valueOf(Constant.strCharacters[index]);
|
|
|
|
|
} else {
|
|
|
|
|
String s = Constant.strChinese[index - Constant.numCharacter];
|
|
|
|
|
plate += Constant.KEY_CHINESE_MAP.get(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
System.err.println("===>" + plate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|