From cd0a01dc66938175ea4defb56a94ac300145db3f Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 4 Nov 2023 23:13:06 +0300 Subject: [PATCH] Primitives for Map and UAV images --- aero_vloc/primitives/__init__.py | 17 +++++++++ aero_vloc/primitives/map.py | 59 +++++++++++++++++++++++++++++++ aero_vloc/primitives/map_tile.py | 34 ++++++++++++++++++ aero_vloc/primitives/uav_image.py | 25 +++++++++++++ aero_vloc/primitives/uav_seq.py | 48 +++++++++++++++++++++++++ 5 files changed, 183 insertions(+) create mode 100644 aero_vloc/primitives/__init__.py create mode 100644 aero_vloc/primitives/map.py create mode 100644 aero_vloc/primitives/map_tile.py create mode 100644 aero_vloc/primitives/uav_image.py create mode 100644 aero_vloc/primitives/uav_seq.py diff --git a/aero_vloc/primitives/__init__.py b/aero_vloc/primitives/__init__.py new file mode 100644 index 0000000..fb872b7 --- /dev/null +++ b/aero_vloc/primitives/__init__.py @@ -0,0 +1,17 @@ +# Copyright (c) 2023, Ivan Moskalenko, Anastasiia Kornilova +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from uav_loc.primitives.map import Map +from uav_loc.primitives.map_tile import MapTile +from uav_loc.primitives.uav_image import UAVImage +from uav_loc.primitives.uav_seq import UAVSeq diff --git a/aero_vloc/primitives/map.py b/aero_vloc/primitives/map.py new file mode 100644 index 0000000..b606be4 --- /dev/null +++ b/aero_vloc/primitives/map.py @@ -0,0 +1,59 @@ +# Copyright (c) 2023, Ivan Moskalenko, Anastasiia Kornilova +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from pathlib import Path + +from uav_loc.primitives.map_tile import MapTile + + +class Map: + """ + The class represents the satellite map required for UAV localization. + It is assumed that the map is divided into tiles. + """ + + def __init__(self, path_to_metadata: Path): + """ + Reads map from metadata file. + File format -- sequence of lines, each line is a single tile. + + The format of a line is as follows: + `filename top_left_lat top_left_lon bottom_right_lat bottom_right_lon` + + :param path_to_metadata: Path to the metadata file + """ + tiles = [] + map_folder = path_to_metadata.parents[0] + with open(path_to_metadata) as file: + lines = file.readlines()[1:] + for line in lines: + ( + filename, + top_left_lat, + top_left_lon, + bottom_right_lat, + bottom_right_lon, + ) = line.split() + map_tile = MapTile( + map_folder / filename, + float(top_left_lat), + float(top_left_lon), + float(bottom_right_lat), + float(bottom_right_lon), + ) + tiles.append(map_tile) + self.tiles = tiles + + def __iter__(self): + for map_tile in self.tiles: + yield map_tile diff --git a/aero_vloc/primitives/map_tile.py b/aero_vloc/primitives/map_tile.py new file mode 100644 index 0000000..64c562a --- /dev/null +++ b/aero_vloc/primitives/map_tile.py @@ -0,0 +1,34 @@ +# Copyright (c) 2023, Ivan Moskalenko, Anastasiia Kornilova +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from pathlib import Path + + +class MapTile: + """ + The class represents one satellite map tile with specified coordinates + """ + + def __init__( + self, + path: Path, + top_left_lat: float, + top_left_lon: float, + bottom_right_lat: float, + bottom_right_lon: float, + ): + self.path = path + self.top_left_lat = top_left_lat + self.top_left_lon = top_left_lon + self.bottom_right_lat = bottom_right_lat + self.bottom_right_lon = bottom_right_lon diff --git a/aero_vloc/primitives/uav_image.py b/aero_vloc/primitives/uav_image.py new file mode 100644 index 0000000..ee48ffc --- /dev/null +++ b/aero_vloc/primitives/uav_image.py @@ -0,0 +1,25 @@ +# Copyright (c) 2023, Ivan Moskalenko, Anastasiia Kornilova +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from pathlib import Path + + +class UAVImage: + """ + The class represents one UAV image with specified groundtruth coordinates + """ + + def __init__(self, path: Path, gt_latitude: float, gt_longitude: float): + self.path = path + self.gt_latitude = gt_latitude + self.gt_longitude = gt_longitude diff --git a/aero_vloc/primitives/uav_seq.py b/aero_vloc/primitives/uav_seq.py new file mode 100644 index 0000000..cf8ad5c --- /dev/null +++ b/aero_vloc/primitives/uav_seq.py @@ -0,0 +1,48 @@ +# Copyright (c) 2023, Ivan Moskalenko, Anastasiia Kornilova +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from pathlib import Path + +from uav_loc.primitives.uav_image import UAVImage + + +class UAVSeq: + """ + The class represents a sequence of frames taken from a UAV + """ + + def __init__(self, path_to_metadata: Path): + """ + Reads sequence of images from metadata file. + File format -- sequence of lines, each line is a single image. + + The format of a line is as follows: + `filename groundtruth_longitude groundtruth_latitude` + + :param path_to_metadata: Path to the metadata file + """ + uav_images = [] + queries_folder = path_to_metadata.parents[0] + with open(path_to_metadata) as file: + lines = file.readlines()[1:] + for line in lines: + filename, longitude, latitude = line.split() + uav_image = UAVImage( + queries_folder / filename, float(latitude), float(longitude) + ) + uav_images.append(uav_image) + self.uav_images = uav_images + + def __iter__(self): + for uav_image in self.uav_images: + yield uav_image