From eb4cb447309c5b0f6bfe1812df711fb8d2e390f5 Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Fri, 13 Sep 2024 08:28:02 -0400 Subject: [PATCH] Add roundtrip example --- cameralib/__init__.py | 3 +++ examples/roundtrip.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 examples/roundtrip.py diff --git a/cameralib/__init__.py b/cameralib/__init__.py index 1d109da..6789b1c 100644 --- a/cameralib/__init__.py +++ b/cameralib/__init__.py @@ -23,6 +23,7 @@ * `Hello World`_ * `X-AnyLabeling annotations to GeoJSON`_ * `Yolov7 annotations to GeoJSON`_ + * `Round Trip`_ Getting Help / Reporting Issues: -------------------------------- @@ -44,6 +45,8 @@ https://github.com/OpenDroneMap/CameraLib/blob/main/examples/anylabeling.py .. _Yolov7 annotations to GeoJSON: https://github.com/OpenDroneMap/CameraLib/blob/main/examples/yolov7.py +.. _Round Trip: + https://github.com/OpenDroneMap/CameraLib/blob/main/examples/roundtrip.py .. _report it: https://github.com/OpenDroneMap/CameraLib/issues .. _`GitHub`: diff --git a/examples/roundtrip.py b/examples/roundtrip.py new file mode 100644 index 0000000..9ea9783 --- /dev/null +++ b/examples/roundtrip.py @@ -0,0 +1,18 @@ +import math +from cameralib import Projector +from cameralib.tests import get_test_dataset + + +p = Projector(get_test_dataset()) +coords = [46.8423725961765, -91.99395518749954] +print(f"Input: {coords}") + +cams = p.world2cams(*coords) +for cam in cams: + if cam['filename'] == 'DJI_0028.JPG': + print(f"X: {cam['x']} Y: {cam['y']}") + output = p.cam2world('DJI_0028.JPG', [(cam['x'], cam['y'])]) + print(f"Output: {output[0]}") + rms = math.sqrt((coords[0] - output[0][0]) ** 2 + (coords[1] - output[0][1]) ** 2) + print(f"Reprojection error: ~{rms / 7.87e-6} meters") +