Skip to content

Commit

Permalink
Primitives for Map and UAV images
Browse files Browse the repository at this point in the history
  • Loading branch information
vnmsklnk committed Nov 4, 2023
1 parent a866632 commit cd0a01d
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
17 changes: 17 additions & 0 deletions aero_vloc/primitives/__init__.py
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions aero_vloc/primitives/map.py
Original file line number Diff line number Diff line change
@@ -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
34 changes: 34 additions & 0 deletions aero_vloc/primitives/map_tile.py
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions aero_vloc/primitives/uav_image.py
Original file line number Diff line number Diff line change
@@ -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
48 changes: 48 additions & 0 deletions aero_vloc/primitives/uav_seq.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit cd0a01d

Please sign in to comment.