@@ -54,12 +54,12 @@ static class Args {
54
54
@ Parameter (names = "--unclip_ratio" , order = 8 ,
55
55
description = "The unclip ratio of the detected text region, which determines the output size." )
56
56
double unclipRatio = 2.0 ;
57
- @ Parameter (names = {"--save" , "-s" }, order = 9 , arity = 1 ,
57
+ @ Parameter (names = {"--save" , "-s" }, order = 9 ,
58
58
description = "Specify to save file with results (i.e. bounding box, confidence level). Invalid in case of camera input." )
59
- boolean save = true ;
60
- @ Parameter (names = {"--viz" , "-v" }, order = 10 , arity = 1 ,
59
+ boolean save ;
60
+ @ Parameter (names = {"--viz" , "-v" }, order = 10 ,
61
61
description = "Specify to open a new window to show results. Invalid in case of camera input." )
62
- boolean viz = true ;
62
+ boolean viz ;
63
63
@ Parameter (names = {"--backend" , "-bt" }, order = 11 ,
64
64
description = "Choose one of computation backends:" +
65
65
" 0: OpenCV implementation + CPU," +
@@ -93,8 +93,12 @@ public PPOCRDet(String modelPath, Size inputSize,
93
93
}
94
94
95
95
public Map .Entry <PointVectorVector , FloatPointer > infer (Mat image ) {
96
- assert image .rows () == inputSize .height () : "height of input image != net input size" ;
97
- assert image .cols () == inputSize .width () : "width of input image != net input size" ;
96
+ if (image .rows () != inputSize .height ()) {
97
+ throw new IllegalArgumentException ("height of input image != net input size" );
98
+ }
99
+ if (image .cols () != inputSize .width ()) {
100
+ throw new IllegalArgumentException ("width of input image != net input size" );
101
+ }
98
102
final PointVectorVector pt = new PointVectorVector ();
99
103
final FloatPointer confidences = new FloatPointer ();
100
104
model .detect (image , pt , confidences );
@@ -125,8 +129,7 @@ static Mat visualize(Mat image, Map.Entry<PointVectorVector, FloatPointer> resul
125
129
}
126
130
127
131
/**
128
- * Execute:
129
- * mvn compile exec:java -Dexec.mainClass=demo -q -Dexec.args="--help"
132
+ * Execute: mvn compile exec:java -q -Dexec.args=""
130
133
*/
131
134
public static void main (String [] argv ) {
132
135
final Args args = new Args ();
@@ -140,7 +143,9 @@ public static void main(String[] argv) {
140
143
return ;
141
144
}
142
145
final int [] backendTargetPair = backendTargetPairs [args .backend ];
143
- assert args .model != null && !args .model .isEmpty () : "Model name is empty" ;
146
+ if (args .model == null || args .model .isEmpty ()) {
147
+ throw new IllegalArgumentException ("Model name is empty" );
148
+ }
144
149
final Size inpSize = new Size (args .width , args .height );
145
150
146
151
final PPOCRDet model = new PPOCRDet (args .model , inpSize ,
@@ -153,7 +158,9 @@ public static void main(String[] argv) {
153
158
} else {
154
159
cap .open (0 );
155
160
}
156
- assert cap .isOpened () : "Cannot open video or file" ;
161
+ if (!cap .isOpened ()) {
162
+ throw new IllegalArgumentException ("Cannot open video or file" );
163
+ }
157
164
Mat originalImage = new Mat ();
158
165
159
166
final OpenCVFrameConverter .ToMat converter = new OpenCVFrameConverter .ToMat ();
@@ -167,9 +174,8 @@ public static void main(String[] argv) {
167
174
final Scalar boxColor = new Scalar (0 , 255 , 0 , 0 );
168
175
final Scalar textColor = new Scalar (0 , 0 , 255 , 0 );
169
176
final TickMeter tm = new TickMeter ();
170
- while (cap .read (originalImage )) {
171
- cap .read (originalImage );
172
177
178
+ while (cap .read (originalImage )) {
173
179
final int originalW = originalImage .cols ();
174
180
final int originalH = originalImage .rows ();
175
181
final double scaleHeight = originalH / (double ) inpSize .height ();
@@ -179,7 +185,7 @@ public static void main(String[] argv) {
179
185
180
186
// inference
181
187
tm .start ();
182
- Map .Entry <PointVectorVector , FloatPointer > results = model .infer (image );
188
+ final Map .Entry <PointVectorVector , FloatPointer > results = model .infer (image );
183
189
tm .stop ();
184
190
// Scale the results bounding box
185
191
final PointVectorVector pvv = results .getKey ();
0 commit comments