From 17ac89d17fa9193310f85147c1e421e206be3fab Mon Sep 17 00:00:00 2001 From: bob joe Date: Sat, 20 Apr 2024 13:00:15 -0500 Subject: [PATCH] fix #130 incorrect camera intrinsics matching --- .../main/java/com/openathena/MetadataExtractor.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/openathena/MetadataExtractor.java b/app/src/main/java/com/openathena/MetadataExtractor.java index ad64c9b2..d87092c0 100644 --- a/app/src/main/java/com/openathena/MetadataExtractor.java +++ b/app/src/main/java/com/openathena/MetadataExtractor.java @@ -138,18 +138,21 @@ public static JSONObject getMatchingDrone(ExifInterface exif) { throw new RuntimeException("could not determine width and height of image!"); } - int smallestDifference = Integer.MAX_VALUE; + double smallestDifference = Double.MAX_VALUE; JSONObject closestDrone = null; for (int i = 0; i < matchingDrones.length(); i++) { try { JSONObject drone = matchingDrones.getJSONObject(i); - int droneWidth = drone.getInt("widthPixels"); + double droneWidth = drone.getInt("widthPixels"); - int difference = (int) Math.abs(droneWidth - targetWidth); - if (difference < smallestDifference) { + double difference_ratio = droneWidth / targetWidth; + if (difference_ratio < 1.0d) { + difference_ratio = 1 / difference_ratio; + } + if (difference_ratio < smallestDifference) { closestDrone = drone; - smallestDifference = difference; + smallestDifference = difference_ratio; } } catch (JSONException e) { return null;