-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eac705c
commit a3e4e97
Showing
11 changed files
with
256 additions
and
71 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/home/roboticslab/Developer/image2overlays/.conda/bin/python | ||
from PIL import Image | ||
import piexif | ||
|
||
# Load the image from file path | ||
jpg_image_path = '/home/roboticslab/Developer/image2overlays/TestImages/raw/S1078749.JPG' | ||
|
||
# Open the image using PIL | ||
jpg_image = Image.open(jpg_image_path) | ||
|
||
# Extract EXIF data | ||
exif_data = piexif.load(jpg_image.info['exif']) | ||
|
||
# GPS information is in the 'GPSInfo' field of the EXIF data | ||
gps_info = exif_data.get('GPSInfo') | ||
|
||
# Define a helper function to convert GPS coordinates to a human-readable format | ||
def convert_to_degrees(value): | ||
"""Convert GPS coordinates stored in the EXIF to degrees""" | ||
d, m, s = value | ||
return d + (m / 60.0) + (s / 3600.0) | ||
|
||
# Check if GPSInfo tag is present | ||
if gps_info: | ||
# Extract latitude and longitude in EXIF's specific format | ||
latitude = gps_info.get(2) | ||
longitude = gps_info.get(4) | ||
|
||
# Convert latitude and longitude to degrees if they are present | ||
if latitude and longitude: | ||
lat_degrees = convert_to_degrees(latitude) | ||
long_degrees = convert_to_degrees(longitude) | ||
|
||
# Determine the sign based on the reference value | ||
lat_ref = gps_info.get(1) | ||
long_ref = gps_info.get(3) | ||
|
||
if lat_ref == 'S': | ||
lat_degrees = -lat_degrees | ||
if long_ref == 'W': | ||
long_degrees = -long_degrees | ||
|
||
# Print out the geolocation information | ||
geolocation = { | ||
'Latitude': lat_degrees, | ||
'Longitude': long_degrees | ||
} | ||
else: | ||
geolocation = "No geolocation information found." | ||
|
||
print(geolocation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
[Settings] | ||
image_path = /home/roboticslab/Downloads/2d_up_9_to_8_test/images | ||
output_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-26_23-06-36 | ||
output_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-28_21-23-17 | ||
output_dir_message = output_directory is auto-generated. | ||
|
||
[CrackSegmentation] | ||
config = config_bo.json | ||
model = saved/UperNet/01-17_12-55/best_model.pth | ||
mask_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-26_23-06-36/crackmask | ||
mask_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-28_21-23-17/crackmask | ||
mask_dir_message = mask_directory is auto-generated. | ||
|
||
[StainSegmentation] | ||
config = config_stain.json | ||
model = saved/StainNet/2024-02-26_00-05/best_model.pth | ||
mask_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-26_23-06-36/stainmask | ||
mask_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-28_21-23-17/stainmask | ||
mask_dir_message = mask_directory is auto-generated. | ||
|
||
[CrackOverlay] | ||
overlay_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-26_23-06-36/crackoverlay/images | ||
overlay_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-28_21-23-17/crackoverlay/images | ||
overlay_dir_message = overlay_directory is auto-generated. | ||
|
||
[StainOverlay] | ||
overlay_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-26_23-06-36/stainoverlay/images | ||
overlay_directory = /home/roboticslab/Downloads/2d_up_9_to_8_test/images_out/2024-02-28_21-23-17/stainoverlay/images | ||
overlay_dir_message = overlay_directory is auto-generated. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/home/roboticslab/Developer/image2overlays/.conda/bin/python | ||
import subprocess | ||
import json | ||
|
||
def get_geolocation_with_exiftool(image_path): | ||
command = ["exiftool", "-json", "-GPSLatitude", "-GPSLongitude", "-GPSAltitude", image_path] | ||
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
output = process.stdout | ||
|
||
try: | ||
data = json.loads(output)[0] | ||
return data.get('GPSLatitude'), data.get('GPSLongitude'), data.get('GPSAltitude') | ||
except json.JSONDecodeError: | ||
return None, None, None | ||
|
||
def write_geolocation_with_exiftool(dest_image, latitude, longitude, altitude): | ||
command = [ | ||
"exiftool", | ||
f"-GPSLatitude={latitude}", | ||
f"-GPSLongitude={longitude}", | ||
f"-GPSAltitude={altitude}", | ||
dest_image | ||
] | ||
subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
|
||
def process_single_image(raw_image_path, mask_image_path): | ||
lat, lon, alt = get_geolocation_with_exiftool(raw_image_path) | ||
|
||
if lat and lon and alt: | ||
write_geolocation_with_exiftool(mask_image_path, lat, lon, alt) | ||
print(f"Geolocation information copied from {raw_image_path} to {mask_image_path}.") | ||
else: | ||
print("No geolocation information found in the source image.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!~/anaconda3/bin/python | ||
#Copy geolocation data to crack overlay images | ||
import configparser | ||
import subprocess | ||
from main import log_message, call_in_conda_env | ||
|
||
# Load the configuration file | ||
config = configparser.ConfigParser() | ||
config.read('config.ini') | ||
|
||
# Extract image_path and mask_directory from the config file | ||
image_path = config['Settings']['image_path'] | ||
# Assuming you want to use CrackSegmentation's mask_directory for this example | ||
mask_directory = config['CrackSegmentation']['mask_directory'] | ||
|
||
# The path to your copy_geolocation.py script | ||
copy_geolocation_script_path = 'copy_geolocation.py' | ||
|
||
# Call copy_geolocation.py with the extracted paths | ||
# subprocess.run(['python', copy_geolocation_script_path, image_path, mask_directory], check=True) | ||
call_in_conda_env(f"python {copy_geolocation_script_path} {image_path} {mask_directory}", "/home/roboticslab/Developer/image2overlays/.conda") | ||
|
||
log_message("Copying geolocation info to stain overlay...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import unittest | ||
import subprocess | ||
import json | ||
import os | ||
from copy_geo_exiftool import process_single_image | ||
|
||
class TestImageProcessing(unittest.TestCase): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
# Backup the original mask image | ||
cls.test_raw_image_path = '/home/roboticslab/Developer/image2overlays/TestImages/raw/S1078749.JPG' | ||
cls.test_mask_image_path = '/home/roboticslab/Developer/image2overlays/TestImages/S1078749.JPG' | ||
cls.backup_mask_image_path = f"{cls.test_mask_image_path}_original" | ||
if not os.path.exists(cls.backup_mask_image_path): | ||
os.rename(cls.test_mask_image_path, cls.backup_mask_image_path) | ||
|
||
def get_geolocation_with_exiftool(self, image_path): | ||
# Run exiftool and parse latitude, longitude, and altitude | ||
command = ["exiftool", "-json", "-GPSLatitude", "-GPSLongitude", "-GPSAltitude", image_path] | ||
process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) | ||
output = process.stdout | ||
data = json.loads(output)[0] | ||
return data.get('GPSLatitude'), data.get('GPSLongitude'), data.get('GPSAltitude') | ||
|
||
def test_process_single_image(self): | ||
# Call the function with the test paths | ||
process_single_image(self.test_raw_image_path, self.test_mask_image_path) | ||
|
||
# Get the geolocation data from the mask image after processing | ||
lat, lon, alt = self.get_geolocation_with_exiftool(self.test_mask_image_path) | ||
|
||
# Assert that the geolocation data is not None (indicating that it's been written) | ||
self.assertIsNotNone(lat, "Latitude was not written to the mask image") | ||
self.assertIsNotNone(lon, "Longitude was not written to the mask image") | ||
self.assertIsNotNone(alt, "Altitude was not written to the mask image") | ||
|
||
# Additional assertions can be added to compare with expected values | ||
# For example: | ||
# self.assertEqual(lat, expected_lat) | ||
# self.assertEqual(lon, expected_lon) | ||
# self.assertEqual(alt, expected_alt) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
# Clean up: Restore the original state of the mask image | ||
if os.path.exists(cls.backup_mask_image_path): | ||
os.remove(cls.test_mask_image_path) | ||
os.rename(cls.backup_mask_image_path, cls.test_mask_image_path) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters