File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
DNN-OpenCV-Classification-with-Java Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -82,17 +82,21 @@ public static Mat getPreprocessedImage(String imagePath) {
82
82
return blob ;
83
83
}
84
84
85
- public static void getPredictedClass (Mat classificationResult ) {
85
+ public static String getPredictedClass (Mat classificationResult ) {
86
86
ArrayList <String > imgLabels = new ArrayList <String >();
87
87
try {
88
88
imgLabels = getImgLabels (IMAGENET_CLASSES );
89
89
} catch (IOException ex ) {
90
-
90
+ System .out .printf ("Could not read %s file:%n" , IMAGENET_CLASSES );
91
+ ex .printStackTrace ();
92
+ }
93
+ if (imgLabels .isEmpty ()) {
94
+ return "" ;
91
95
}
92
96
// obtain max prediction result
93
97
Core .MinMaxLocResult mm = Core .minMaxLoc (classificationResult );
94
98
double maxValIndex = mm .maxLoc .x ;
95
- System . out . println ( "Predicted Class: " + imgLabels .get ((int ) maxValIndex ) );
99
+ return imgLabels .get ((int ) maxValIndex );
96
100
}
97
101
98
102
public static void main (String [] args ) {
@@ -115,6 +119,7 @@ public static void main(String[] args) {
115
119
Mat classification = dnnNet .forward ();
116
120
117
121
// decode classification results
118
- DnnOpenCV .getPredictedClass (classification );
122
+ String label = DnnOpenCV .getPredictedClass (classification );
123
+ System .out .println ("Predicted Class: " + label );
119
124
}
120
125
}
You can’t perform that action at this time.
0 commit comments