@@ -49,7 +49,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
49
49
double scene_width = img_scene .cols ();
50
50
//logger.info("Scene height and width: " + scene_height + ", " + scene_width);
51
51
52
- double resizeFactor = 1 ;
52
+ double resizeFactor ;
53
53
if (scene_width < scene_height )
54
54
resizeFactor = scene_width / 750 ;
55
55
else
@@ -66,13 +66,10 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
66
66
resizeFactor = 1 ;
67
67
}
68
68
69
- String jsonResults = null ;
69
+ String jsonResults ;
70
70
try {
71
71
jsonResults = runAkazeMatch (queryImageFile , sceneFile );
72
- } catch (InterruptedException e ) {
73
- e .printStackTrace ();
74
- return null ;
75
- } catch (IOException e ) {
72
+ } catch (InterruptedException | IOException e ) {
76
73
e .printStackTrace ();
77
74
return null ;
78
75
}
@@ -86,14 +83,14 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
86
83
Imgcodecs .imwrite (sceneFile , img_scene );
87
84
88
85
//finding homography
89
- LinkedList <Point > objList = new LinkedList <Point >();
90
- LinkedList <Point > sceneList = new LinkedList <Point >();
86
+ LinkedList <Point > objList = new LinkedList <>();
87
+ LinkedList <Point > sceneList = new LinkedList <>();
91
88
JSONObject jsonObject = getJsonObject (jsonResults );
92
89
if (jsonObject == null ) {
93
90
logger .error ("ERROR: Json file couldn't be processed. " );
94
91
return null ;
95
92
}
96
- JSONArray keypointsPairs = null ;
93
+ JSONArray keypointsPairs ;
97
94
try {
98
95
keypointsPairs = jsonObject .getJSONArray ("keypoint-pairs" );
99
96
} catch (JSONException e ) {
@@ -174,7 +171,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
174
171
bottom_right = objectOnScene [2 ];
175
172
bottom_left = objectOnScene [3 ];
176
173
177
- double initial_ratio = 1.0 ;
174
+ double initial_ratio ;
178
175
if ((rotationAngle == 1.0 ) || (rotationAngle == -1.0 )) {
179
176
initial_ratio = initial_width / initial_height ;
180
177
} else {
@@ -269,10 +266,10 @@ private Mat drawFoundHomography(Mat img_object, String filename, Mat h) {
269
266
Mat obj_corners = new Mat (4 , 1 , CvType .CV_32FC2 );
270
267
Mat scene_corners = new Mat (4 , 1 , CvType .CV_32FC2 );
271
268
272
- obj_corners .put (0 , 0 , new double []{ 0 , 0 } );
273
- obj_corners .put (1 , 0 , new double []{ img_object .cols (), 0 } );
274
- obj_corners .put (2 , 0 , new double []{ img_object .cols (), img_object .rows ()} );
275
- obj_corners .put (3 , 0 , new double []{ 0 , img_object .rows ()} );
269
+ obj_corners .put (0 , 0 , 0 , 0 );
270
+ obj_corners .put (1 , 0 , img_object .cols (), 0 );
271
+ obj_corners .put (2 , 0 , img_object .cols (), img_object .rows ());
272
+ obj_corners .put (3 , 0 , 0 , img_object .rows ());
276
273
277
274
Core .perspectiveTransform (obj_corners , scene_corners , h );
278
275
@@ -341,7 +338,7 @@ private String runAkazeMatch(String object_filename, String scene_filename) thro
341
338
File file = new File (jsonFilename );
342
339
file .getParentFile ().mkdirs ();
343
340
String platformName = System .getProperty ("os.name" );
344
- String akazePath = "" ;
341
+ String akazePath ;
345
342
if (platformName .toLowerCase ().contains ("mac" )) {
346
343
akazePath = "lib/mac/akaze/akaze_match" ;
347
344
} else if (platformName .toLowerCase ().contains ("win" )) {
@@ -357,8 +354,7 @@ private String runAkazeMatch(String object_filename, String scene_filename) thro
357
354
InputStream stdin = proc .getInputStream ();
358
355
InputStreamReader isr = new InputStreamReader (stdin );
359
356
BufferedReader br = new BufferedReader (isr );
360
- String line = null ;
361
- while ((line = br .readLine ()) != null )
357
+ while ((br .readLine ()) != null )
362
358
System .out .print ("" );
363
359
int exitVal = proc .waitFor ();
364
360
if (exitVal != 0 )
@@ -382,16 +378,13 @@ protected static void setupOpenCVEnv() {
382
378
383
379
private JSONObject getJsonObject (String filename ) {
384
380
File jsonFile = new File (filename );
385
- InputStream is = null ;
381
+ InputStream is ;
386
382
try {
387
383
is = new FileInputStream (jsonFile );
388
384
String jsonTxt = IOUtils .toString (is );
389
385
return new JSONObject (jsonTxt );
390
386
391
- } catch (IOException e ) {
392
- e .printStackTrace ();
393
- return null ;
394
- } catch (JSONException e ) {
387
+ } catch (IOException | JSONException e ) {
395
388
e .printStackTrace ();
396
389
return null ;
397
390
}
0 commit comments