1
1
package mmdeploy ;
2
2
3
+ /** @description: the Java API class of Detector. */
3
4
public class Detector {
4
5
static {
5
6
System .loadLibrary ("mmdeploy_java" );
6
7
}
7
8
8
9
private final long handle ;
9
10
11
+ /** @description: Single detection result of a picture. */
10
12
public static class Result {
13
+
14
+ /** Bbox class id. */
11
15
public int label_id ;
16
+
17
+ /** Bbox score. */
12
18
public float score ;
19
+
20
+ /** Bbox coordinates. */
13
21
public Rect bbox ;
22
+
23
+ /** Bbox mask. */
14
24
public InstanceMask mask ;
25
+
26
+ /** Initializes a new instance of the Result class.
27
+ * @param label_id: bbox class id.
28
+ * @param score: bbox score.
29
+ * @param bbox: bbox coordinates.
30
+ * @param mask: bbox mask.
31
+ */
15
32
public Result (int label_id , float score , Rect bbox , InstanceMask mask ) {
16
33
this .label_id = label_id ;
17
34
this .score = score ;
@@ -20,13 +37,30 @@ public Result(int label_id, float score, Rect bbox, InstanceMask mask) {
20
37
}
21
38
}
22
39
23
- public Detector (String modelPath , String deviceName , int deviceId ) {
40
+ /** Initializes a new instance of the Detector class.
41
+ * @param modelPath: model path.
42
+ * @param deviceName: device name.
43
+ * @param deviceId: device ID.
44
+ * @exception Exception: create Detector failed exception.
45
+ */
46
+ public Detector (String modelPath , String deviceName , int deviceId ) throws Exception {
24
47
handle = create (modelPath , deviceName , deviceId );
48
+ if (handle == -1 ) {
49
+ throw new Exception ("Create Detector failed!" );
50
+ }
25
51
}
26
52
27
- public Result [][] apply (Mat [] images ) {
53
+ /** Get information of each image in a batch.
54
+ * @param images: input mats.
55
+ * @return: results of each input mat.
56
+ * @exception Exception: apply Detector failed exception.
57
+ */
58
+ public Result [][] apply (Mat [] images ) throws Exception {
28
59
int [] counts = new int [images .length ];
29
60
Result [] results = apply (handle , images , counts );
61
+ if (results == null ) {
62
+ throw new Exception ("Apply Detector failed!" );
63
+ }
30
64
Result [][] rets = new Result [images .length ][];
31
65
int offset = 0 ;
32
66
for (int i = 0 ; i < images .length ; ++i ) {
@@ -40,12 +74,22 @@ public Result[][] apply(Mat[] images) {
40
74
return rets ;
41
75
}
42
76
43
- public Result [] apply (Mat image ) {
77
+ /** Get information of one image.
78
+ * @param image: input mat.
79
+ * @return: result of input mat.
80
+ * @exception Exception: apply Detector failed exception.
81
+ */
82
+ public Result [] apply (Mat image ) throws Exception {
44
83
int [] counts = new int [1 ];
45
84
Mat [] images = new Mat []{image };
46
- return apply (handle , images , counts );
85
+ Result [] results = apply (handle , images , counts );
86
+ if (results == null ) {
87
+ throw new Exception ("Apply Detector failed!" );
88
+ }
89
+ return results ;
47
90
}
48
91
92
+ /** Release the instance of Detector. */
49
93
public void release () {
50
94
destroy (handle );
51
95
}
0 commit comments