@@ -49,7 +49,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
4949 double scene_width = img_scene .cols ();
5050 //logger.info("Scene height and width: " + scene_height + ", " + scene_width);
5151
52- double resizeFactor = 1 ;
52+ double resizeFactor ;
5353 if (scene_width < scene_height )
5454 resizeFactor = scene_width / 750 ;
5555 else
@@ -66,13 +66,10 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
6666 resizeFactor = 1 ;
6767 }
6868
69- String jsonResults = null ;
69+ String jsonResults ;
7070 try {
7171 jsonResults = runAkazeMatch (queryImageFile , sceneFile );
72- } catch (InterruptedException e ) {
73- e .printStackTrace ();
74- return null ;
75- } catch (IOException e ) {
72+ } catch (InterruptedException | IOException e ) {
7673 e .printStackTrace ();
7774 return null ;
7875 }
@@ -86,14 +83,14 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
8683 Imgcodecs .imwrite (sceneFile , img_scene );
8784
8885 //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 <>();
9188 JSONObject jsonObject = getJsonObject (jsonResults );
9289 if (jsonObject == null ) {
9390 logger .error ("ERROR: Json file couldn't be processed. " );
9491 return null ;
9592 }
96- JSONArray keypointsPairs = null ;
93+ JSONArray keypointsPairs ;
9794 try {
9895 keypointsPairs = jsonObject .getJSONArray ("keypoint-pairs" );
9996 } catch (JSONException e ) {
@@ -174,7 +171,7 @@ protected ImageLocation findImage(String queryImageFile, String sceneFile, doubl
174171 bottom_right = objectOnScene [2 ];
175172 bottom_left = objectOnScene [3 ];
176173
177- double initial_ratio = 1.0 ;
174+ double initial_ratio ;
178175 if ((rotationAngle == 1.0 ) || (rotationAngle == -1.0 )) {
179176 initial_ratio = initial_width / initial_height ;
180177 } else {
@@ -269,10 +266,10 @@ private Mat drawFoundHomography(Mat img_object, String filename, Mat h) {
269266 Mat obj_corners = new Mat (4 , 1 , CvType .CV_32FC2 );
270267 Mat scene_corners = new Mat (4 , 1 , CvType .CV_32FC2 );
271268
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 ());
276273
277274 Core .perspectiveTransform (obj_corners , scene_corners , h );
278275
@@ -341,7 +338,7 @@ private String runAkazeMatch(String object_filename, String scene_filename) thro
341338 File file = new File (jsonFilename );
342339 file .getParentFile ().mkdirs ();
343340 String platformName = System .getProperty ("os.name" );
344- String akazePath = "" ;
341+ String akazePath ;
345342 if (platformName .toLowerCase ().contains ("mac" )) {
346343 akazePath = "lib/mac/akaze/akaze_match" ;
347344 } else if (platformName .toLowerCase ().contains ("win" )) {
@@ -357,8 +354,7 @@ private String runAkazeMatch(String object_filename, String scene_filename) thro
357354 InputStream stdin = proc .getInputStream ();
358355 InputStreamReader isr = new InputStreamReader (stdin );
359356 BufferedReader br = new BufferedReader (isr );
360- String line = null ;
361- while ((line = br .readLine ()) != null )
357+ while ((br .readLine ()) != null )
362358 System .out .print ("" );
363359 int exitVal = proc .waitFor ();
364360 if (exitVal != 0 )
@@ -382,16 +378,13 @@ protected static void setupOpenCVEnv() {
382378
383379 private JSONObject getJsonObject (String filename ) {
384380 File jsonFile = new File (filename );
385- InputStream is = null ;
381+ InputStream is ;
386382 try {
387383 is = new FileInputStream (jsonFile );
388384 String jsonTxt = IOUtils .toString (is );
389385 return new JSONObject (jsonTxt );
390386
391- } catch (IOException e ) {
392- e .printStackTrace ();
393- return null ;
394- } catch (JSONException e ) {
387+ } catch (IOException | JSONException e ) {
395388 e .printStackTrace ();
396389 return null ;
397390 }
0 commit comments