Object Detection using Template

- Main Page
- Packages
- Classes
- Files

- File List

All Classes Namespaces Files Functions Variables
StartRM.java
Go to the documentation of this file.
1 package cz.vutbr.feec.novak68;
2
3 import java.io.File;
4 import java.io.IOException;
5 import java.util.List;
6 import java.util.Vector;
7
8 import com.rapidminer.Process;
9 import com.rapidminer.RapidMiner;
10 import com.rapidminer.RapidMiner.ExecutionMode;
11 import com.rapidminer.example.Attribute;
12 import com.rapidminer.example.Attributes;
13 import com.rapidminer.example.Example;
14 import com.rapidminer.example.ExampleSet;
15 import com.rapidminer.example.table.AttributeFactory;
16 import com.rapidminer.example.table.DataRow;
17 import com.rapidminer.example.table.DataRowFactory;
18 import com.rapidminer.example.table.MemoryExampleTable;
19 import com.rapidminer.operator.IOContainer;
20 import com.rapidminer.operator.OperatorException;
21 import com.rapidminer.tools.Ontology;
22 import com.rapidminer.tools.XMLException;
23
28 public class StartRM {
29
30 public static void main(String[] args) {
31 String sep = File.separator;
32 String rmpFile = "rapidminer" + sep + "labelProc.rmp";
33
34 System.out.println("Starting RapidMiner...");
35 if (System.getProperty("os.name").toLowerCase().equals("linux"))
36 System.setProperty("rapidminer.home", "/opt/rapidminer");
37 RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
38 RapidMiner.init();
39 ExampleSet inEs = ExampleSetHeader();
40 addValues("", inEs, "xxxxxx", 878.8343271962161, 104.66135867644753, (int)(-75.0), (int)(-73.0), (int)(-72.0), (int)(-63.0), (int)(-28.0), (int)(19.0));
41 Process process = null;
42 IOContainer outputs = null;
43 IOContainer inputs = new IOContainer(inEs);
44 try {
45 process = new Process(new File(rmpFile));
46 outputs = process.run(inputs);
47 } catch (IOException | XMLException | OperatorException e) {
48 e.printStackTrace();
49 }
50 ExampleSet es = (ExampleSet) outputs.getElementAt(0);
51 // System.out.println(es.getAttributes().getPredictedLabel().);
52 for (Example example : es) {
53 // double value = Double.parseDouble(example.getValueAsString(es.getAttributes().getRegular("otherElementC")));
54 // System.out.println(value);
55
56 // String file = example.getValueAsString(es.getAttributes().get("fileName"));
57 System.out.println(example.getValueAsString(es.getAttributes().getRegular("coordinates")));
58 System.out.println(example.getValueAsString(es.getAttributes().getRegular("simpleC")));
59 System.out.println(example.getValueAsString(es.getAttributes().getRegular("symetryC")));
60 System.out.println(example.getValueAsString(es.getAttributes().getRegular("xsymetry")));
61 System.out.println(example.getValueAsString(es.getAttributes().getRegular("ysymetry")));
62 System.out.println(example.getValueAsString(es.getAttributes().getRegular("allElementC")));
63 System.out.println(example.getValueAsString(es.getAttributes().getRegular("hElementC")));
64 System.out.println(example.getValueAsString(es.getAttributes().getRegular("vElementC")));
65 System.out.println(example.getValueAsString(es.getAttributes().getRegular("otherElementC")));
66 System.out.println("prediction: " + example.getValueAsString(es.getAttributes().getPredictedLabel()));
67 System.out.println("confidence p: " + example.getValueAsString(es.getAttributes().getConfidence("p")));
68 System.out.println("confidence n: " + example.getValueAsString(es.getAttributes().getConfidence("n")));
69
70
71 // String prediction = example.getValueAsString(es.getAttributes().getPredictedLabel());
72 // System.out.println(file + "; =" + prediction);
73 }
74
75 }
76
77
78 private static ExampleSet addValues (String clazz, ExampleSet exampleSet, String coordinates,
79 double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC,int vElementC, int otherElementC) {
80
81 char decimalSeperator = '.';
82 DataRowFactory ROW_FACTORY = new DataRowFactory(0, decimalSeperator);
83 MemoryExampleTable table = (MemoryExampleTable) exampleSet
84 .getExampleTable();
85
86 int numOfAttrib = table.getNumberOfAttributes();
87
88 Object values[] = new Object[numOfAttrib];
89
90 values[0] = clazz;
91 values[1] = coordinates;
92 values[2] = simpleC;
93 values[3] = symetryC;
94 values[4] = xsymetry;
95 values[5] = ysymetry;
96 values[6] = allElementC;
97 values[7] = hElementC;
98 values[8] = vElementC;
99 values[9] = otherElementC;
100
101 DataRow row = ROW_FACTORY.create(values, table.getAttributes());
102 table.addDataRow(row);
103 return exampleSet;
104 }
105
106 private static ExampleSet ExampleSetHeader() {
107 List<Attribute> attributes = new Vector<Attribute>();
108
109 // Attribute label = null;
110 Attribute prediction = null;
111
112 // Attribute att = AttributeFactory.createAttribute("class",
113 // Ontology.NOMINAL);
114 // attributes.add(att);
115 // label = att;
116 // att.setName(Attributes.LABEL_NAME);
117
118 Attribute attPred = AttributeFactory.createAttribute("prediction",
119 Ontology.NOMINAL);
120 attributes.add(attPred);
121 prediction = attPred;
122 attPred.setName(Attributes.PREDICTION_NAME);
123
124 Attribute att2 = AttributeFactory.createAttribute("coordinates",
125 Ontology.STRING);
126 attributes.add(att2);
127 Attribute att3 = AttributeFactory.createAttribute("simpleC",
128 Ontology.REAL);
129 attributes.add(att3);
130 Attribute att4 = AttributeFactory.createAttribute("symetryC",
131 Ontology.REAL);
132 attributes.add(att4);
133 Attribute att5 = AttributeFactory.createAttribute("xsymetry",
134 Ontology.INTEGER);
135 attributes.add(att5);
136 Attribute att6 = AttributeFactory.createAttribute("ysymetry",
137 Ontology.INTEGER);
138 attributes.add(att6);
139 Attribute att7 = AttributeFactory.createAttribute("allElementC",
140 Ontology.INTEGER);
141 attributes.add(att7);
142 Attribute att8 = AttributeFactory.createAttribute("hElementC",
143 Ontology.INTEGER);
144 attributes.add(att8);
145 Attribute att9 = AttributeFactory.createAttribute("vElementC",
146 Ontology.INTEGER);
147 attributes.add(att9);
148 Attribute att10 = AttributeFactory.createAttribute("otherElementC",
149 Ontology.INTEGER);
150 attributes.add(att10);
151 Attribute attConfidence = AttributeFactory.createAttribute("confidence",
152 Ontology.NUMERICAL);
153 attConfidence.setName(Attributes.CONFIDENCE_NAME);
154 attributes.add(attConfidence);
155
156 MemoryExampleTable table = new MemoryExampleTable(attributes);
157
158 ExampleSet es = table.createExampleSet();
159 // es.getAttributes().setLabel(label);
160 es.getAttributes().setPredictedLabel(prediction);
161
162 return es;
163 }
164
165 }
cz.vutbr.feec.novak68.StartRM.addValues
static ExampleSet addValues(String clazz, ExampleSet exampleSet, String coordinates, double simpleC, double symetryC, int xsymetry, int ysymetry, int allElementC, int hElementC, int vElementC, int otherElementC)
Definition: StartRM.java:78
cz.vutbr.feec.novak68.StartRM.main
static void main(String[] args)
Definition: StartRM.java:30
cz.vutbr.feec.novak68.StartRM
Definition: StartRM.java:28
cz.vutbr.feec.novak68.StartRM.ExampleSetHeader
static ExampleSet ExampleSetHeader()
Definition: StartRM.java:106