Merge pull request #1552 from smathermather/static-masking

Static masking
pull/1553/head
Piero Toffanin 2022-11-14 23:31:33 -05:00 zatwierdzone przez GitHub
commit e67b094a97
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
3 zmienionych plików z 92 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 APPF-ANU
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Wyświetl plik

@ -0,0 +1,9 @@
# Semi-automated Masking for 360 images
For usage with 360 images and Open Drone Map (ODM) to mask out the tripod/user/camera mount. 360 models in ODM can be made from 360 images, but unless you mask out the camera mount there will be repeated artifacts along the camera path. ODM supports image masking but requires a mask for each image. Since the 360 camera is generally on a fixed mount (bike helmet, moving tripod, etc), you can make one mask and then duplicate this for all images, but this is tedious to do by hand.
This snippet takes the file path of a single image mask and duplicates it for all images in the dataset. After creating the masks, process the original images and the masks together in ODM you'll get a clean model with the camera mount artifacts eliminated.
Before using this code snippet, open one of your 360 images in an image editor and mask out the helmet or tripod, etc at the bottom of your image. Save this image as a png and then use it as the mask image that will be duplicated for all images in the dataset.
See https://docs.opendronemap.org/masks/ for more details on mask creation.

Wyświetl plik

@ -0,0 +1,62 @@
#!/usr/bin/env python3
import sys
import os
import PIL
from PIL import Image, ExifTags
import shutil
from tqdm import tqdm
import argparse
parser = argparse.ArgumentParser()
# Usage:
# python exif_renamer.py <path to folder of images to rename> <output folder>
parser.add_argument("file_dir", help="input folder of images")
parser.add_argument("output_dir", help="output folder to copy images to")
parser.add_argument("mask_file", help="filename or path to Mask file to be duplicated for all images")
parser.add_argument("-f", "--force", help="don't ask for confirmation", action="store_true")
args = parser.parse_args()
file_dir = args.file_dir
mask_file_path = args.mask_file
output_dir = args.output_dir
file_count = len(os.listdir(file_dir))
if args.force is False:
print("Input dir: " + str(file_dir))
print("Output folder: " + str(output_dir) + " (" + str(file_count) + " files)")
confirmation = input("Confirm processing [Y/N]: ")
if confirmation.lower() in ["y"]:
pass
else:
sys.exit()
os.makedirs(output_dir, exist_ok=True)
no_exif_n = 0
# Uses tqdm() for the progress bar, if not needed swap with
# for filename in os.listdir(file_dir):
for filename in tqdm(os.listdir(file_dir)):
old_path = mask_file_path
#print(mask_file_path)
file_name, file_ext = os.path.splitext(filename)
try:
img = Image.open(old_path)
except PIL.UnidentifiedImageError as img_err:
# if it tries importing a file it can't read as an image
# can be commented out if you just wanna skip errors
sys.stderr.write(str(img_err) + "\n")
continue
new_path = os.path.join(output_dir, file_name + "_mask" + file_ext)
#print(new_path) # debugging
shutil.copy(old_path, new_path)
print("Done!")