Spaces:
Running
Running
Handle rotated images in the demo
Browse files- maploc/demo.py +16 -15
- maploc/utils/exif.py +5 -3
maploc/demo.py
CHANGED
@@ -70,22 +70,8 @@ def read_input_image(
|
|
70 |
tile_size_meters: int = 64,
|
71 |
):
|
72 |
image = read_image(image_path)
|
73 |
-
|
74 |
-
roll_pitch = None
|
75 |
-
if calibrator is not None:
|
76 |
-
roll_pitch, fov = image_calibration(image_path)
|
77 |
-
else:
|
78 |
-
logger.info("Could not call PerspectiveFields, maybe install gradio_client?")
|
79 |
-
if roll_pitch is not None:
|
80 |
-
logger.info("Using (roll, pitch) %s.", roll_pitch)
|
81 |
-
|
82 |
with open(image_path, "rb") as fid:
|
83 |
exif = EXIF(fid, lambda: image.shape[:2])
|
84 |
-
camera = camera_from_exif(exif, fov)
|
85 |
-
if camera is None:
|
86 |
-
raise ValueError(
|
87 |
-
"No camera intrinsics found in the EXIF, provide an FoV guess."
|
88 |
-
)
|
89 |
|
90 |
latlon = None
|
91 |
if prior_latlon is not None:
|
@@ -110,10 +96,25 @@ def read_input_image(
|
|
110 |
logger.info("Could not find any prior location in the image EXIF metadata.")
|
111 |
if latlon is None:
|
112 |
raise ValueError(
|
113 |
-
"No location prior given
|
|
|
114 |
)
|
115 |
latlon = np.array(latlon)
|
116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
proj = Projection(*latlon)
|
118 |
center = proj.project(latlon)
|
119 |
bbox = BoundaryBox(center, center) + tile_size_meters
|
|
|
70 |
tile_size_meters: int = 64,
|
71 |
):
|
72 |
image = read_image(image_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
with open(image_path, "rb") as fid:
|
74 |
exif = EXIF(fid, lambda: image.shape[:2])
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
latlon = None
|
77 |
if prior_latlon is not None:
|
|
|
96 |
logger.info("Could not find any prior location in the image EXIF metadata.")
|
97 |
if latlon is None:
|
98 |
raise ValueError(
|
99 |
+
"No location prior given or found in the image EXIF metadata: "
|
100 |
+
"maybe provide the name of a street, building or neighborhood?"
|
101 |
)
|
102 |
latlon = np.array(latlon)
|
103 |
|
104 |
+
roll_pitch = None
|
105 |
+
if calibrator is not None:
|
106 |
+
roll_pitch, fov = image_calibration(image_path)
|
107 |
+
else:
|
108 |
+
logger.info("Could not call PerspectiveFields, maybe install gradio_client?")
|
109 |
+
if roll_pitch is not None:
|
110 |
+
logger.info("Using (roll, pitch) %s.", roll_pitch)
|
111 |
+
|
112 |
+
camera = camera_from_exif(exif, fov)
|
113 |
+
if camera is None:
|
114 |
+
raise ValueError(
|
115 |
+
"No camera intrinsics found in the EXIF, provide an FoV guess."
|
116 |
+
)
|
117 |
+
|
118 |
proj = Projection(*latlon)
|
119 |
center = proj.project(latlon)
|
120 |
bbox = BoundaryBox(center, center) + tile_size_meters
|
maploc/utils/exif.py
CHANGED
@@ -87,7 +87,7 @@ def unescape_string(s) -> str:
|
|
87 |
|
88 |
class EXIF:
|
89 |
def __init__(
|
90 |
-
self, fileobj, image_size_loader, use_exif_size=True, name=None
|
91 |
) -> None:
|
92 |
self.image_size_loader = image_size_loader
|
93 |
self.use_exif_size = use_exif_size
|
@@ -97,7 +97,9 @@ class EXIF:
|
|
97 |
self.fileobj_name = self.fileobj.name if name is None else name
|
98 |
|
99 |
def extract_image_size(self) -> Tuple[int, int]:
|
100 |
-
if
|
|
|
|
|
101 |
self.use_exif_size
|
102 |
and "EXIF ExifImageWidth" in self.tags
|
103 |
and "EXIF ExifImageLength" in self.tags
|
@@ -116,7 +118,7 @@ class EXIF:
|
|
116 |
int(self.tags["Image ImageLength"].values[0]),
|
117 |
)
|
118 |
else:
|
119 |
-
|
120 |
return width, height
|
121 |
|
122 |
def _decode_make_model(self, value) -> str:
|
|
|
87 |
|
88 |
class EXIF:
|
89 |
def __init__(
|
90 |
+
self, fileobj, image_size_loader=None, use_exif_size=True, name=None
|
91 |
) -> None:
|
92 |
self.image_size_loader = image_size_loader
|
93 |
self.use_exif_size = use_exif_size
|
|
|
97 |
self.fileobj_name = self.fileobj.name if name is None else name
|
98 |
|
99 |
def extract_image_size(self) -> Tuple[int, int]:
|
100 |
+
if self.image_size_loader is not None:
|
101 |
+
height, width = self.image_size_loader()
|
102 |
+
elif (
|
103 |
self.use_exif_size
|
104 |
and "EXIF ExifImageWidth" in self.tags
|
105 |
and "EXIF ExifImageLength" in self.tags
|
|
|
118 |
int(self.tags["Image ImageLength"].values[0]),
|
119 |
)
|
120 |
else:
|
121 |
+
raise ValueError("Missing image size in EXIF tags or loader.")
|
122 |
return width, height
|
123 |
|
124 |
def _decode_make_model(self, value) -> str:
|