File tree 2 files changed +16
-3
lines changed
core/src/main/java/edu/wpi/grip/core/sources
ui/src/main/java/edu/wpi/grip/ui/pipeline
2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 13
13
14
14
import org .bytedeco .javacpp .opencv_objdetect .CascadeClassifier ;
15
15
16
+ import java .io .IOException ;
17
+ import java .nio .file .Files ;
18
+ import java .nio .file .Paths ;
16
19
import java .util .List ;
17
20
import java .util .Properties ;
18
21
22
+ import static com .google .common .base .Preconditions .checkArgument ;
23
+
19
24
/**
20
25
* A source for the path to a XML classifier file (e.g. haarcascade_face_default.xml).
21
26
*/
@@ -75,8 +80,16 @@ public Properties getProperties() {
75
80
}
76
81
77
82
@ Override
78
- public void initialize () {
79
- classifierSocket .setValue (new CascadeClassifier (filePath ));
83
+ public void initialize () throws IOException {
84
+ if (!Files .exists (Paths .get (filePath ))) {
85
+ throw new IOException ("File does not exist: " + filePath );
86
+ }
87
+ try {
88
+ classifierSocket .setValue (new CascadeClassifier (filePath ));
89
+ } catch (Exception e ) {
90
+ // OpenCV will throw an exception if given malformed XML
91
+ throw new IOException ("Could not load cascade classifier XML" , e );
92
+ }
80
93
}
81
94
82
95
public interface Factory {
Original file line number Diff line number Diff line change @@ -272,7 +272,7 @@ public class AddSourceButton extends MenuButton {
272
272
File file = fc .showOpenDialog (getScene ().getWindow ());
273
273
if (file != null ) {
274
274
ClassifierSource source = classifierSourceFactory .create (file .getAbsolutePath ());
275
- source .initialize ();
275
+ source .initializeSafely ();
276
276
eventBus .post (new SourceAddedEvent (source ));
277
277
}
278
278
});
You can’t perform that action at this time.
0 commit comments