1 |
|
---|
2 | import java.io.File;
|
---|
3 | import java.io.BufferedReader;
|
---|
4 | import java.io.BufferedWriter;
|
---|
5 | import java.io.FileReader;
|
---|
6 | import java.io.FileWriter;
|
---|
7 |
|
---|
8 |
|
---|
9 | public class javaAccuracyCalculator{
|
---|
10 |
|
---|
11 | public static void main(String[] args) {
|
---|
12 |
|
---|
13 | try {
|
---|
14 | if (args.length != 3) {
|
---|
15 | System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>");
|
---|
16 | }
|
---|
17 | else {
|
---|
18 | String inputFilename = args[0];
|
---|
19 | String classifierType = args[1];
|
---|
20 | String outputFilename = args[2];
|
---|
21 | FileReader fileReader = new FileReader(inputFilename);
|
---|
22 | BufferedReader buf = new BufferedReader(fileReader);
|
---|
23 | FileWriter fw = new FileWriter(outputFilename);
|
---|
24 | String line = null;
|
---|
25 | String[] item;
|
---|
26 | float accuracyRate = 0;
|
---|
27 | int trueCount = 0;
|
---|
28 | int lineCount = 0;
|
---|
29 |
|
---|
30 | //RENAME CLASSIFIER NUMBER TO ACTUALL CLASSIFIER
|
---|
31 | if(classifierType.equals("1")){classifierType = "Probabilistic HoughLines";}
|
---|
32 |
|
---|
33 | //Splits into each record, since readLine splits by "\n"
|
---|
34 | while ((line = buf.readLine()) != null) {
|
---|
35 | lineCount++;
|
---|
36 | //Splits by tab, leaves "" for every blank entry
|
---|
37 | item = line.split("\t");
|
---|
38 | //Check first element (true or false)
|
---|
39 | if(item[0].equals("1")){
|
---|
40 | trueCount++;
|
---|
41 | }
|
---|
42 | }
|
---|
43 | accuracyRate = ((float)trueCount/(float)lineCount)*(float)100;
|
---|
44 | fw.write("Classifier:" + classifierType + "\t" + accuracyRate + "%" + "\n");
|
---|
45 | buf.close();
|
---|
46 | fw.close();
|
---|
47 |
|
---|
48 | //Read in log.txt, grab first item in array of each line
|
---|
49 | //counter for everytime have readline
|
---|
50 |
|
---|
51 | //Calculate accuracy rate
|
---|
52 |
|
---|
53 | }
|
---|
54 | }
|
---|
55 | catch(Exception e){
|
---|
56 | System.err.println(e);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|