Commit 512b6785 authored by Clément Pinard's avatar Clément Pinard
Browse files

add LAS file conversion and gps projection

parent a5c21661
from pyproj import Proj
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from path import Path
from tqdm import tqdm
from edit_exif import get_gps_location
import numpy as np
parser = ArgumentParser(description='extract XYZ data from exif and substract cloud centroid to register them',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('--root', metavar='DIR',
help='path to video folder root')
parser.add_argument('--centroid_path')
parser.add_argument('--system', default='epsg:2154')
parser.add_argument('--output', metavar='PATH', default='images.txt')
def main():
args = parser.parse_args()
root = Path(args.root)
images = sorted(root.files('*.jpg'))
if args.centroid_path is not None:
centroid = np.loadtxt(args.centroid_path)
else:
centroid = np.zeros(3)
proj = Proj(args.system)
result = []
for img in tqdm(images):
loc = get_gps_location(img)
if loc is None:
continue
lat, lon, alt = loc
x, y = proj(lon, lat)
pos = np.array([x, y, alt]) - centroid
result.append('{} {} {} {}\n'.format(img.basename(), *pos))
with open(args.output, 'w') as f:
f.writelines(result)
if __name__ == '__main__':
main()
from pyntcloud import PyntCloud
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from path import Path
import numpy as np
parser = ArgumentParser(description='Convert las cloud to ply along with centroid',
formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('las',
help='path to video folder root')
parser.add_argument('--output_ply', metavar='PATH')
parser.add_argument('--output_txt', metavar='PATH')
def main():
args = parser.parse_args()
las_path = Path(args.las)
if args.output_ply is None:
ply_path = las_path.stripext() + '_converted.ply'
else:
ply_path = args.output_ply
if args.output_txt is None:
txt_path = las_path.stripext() + '_centroid.txt'
else:
txt_path = args.output_txt
cloud = PyntCloud.from_file(las_path)
print("Las file with {:,} points "
"(centroid : [{:.2f}, {:.2f}, {:.2f}] in km) "
"successfully loaded".format(len((cloud.points)), *(cloud.centroid/1000)))
np.savetxt(txt_path, cloud.centroid)
xyz = cloud.points[['x', 'y', 'z']]
cloud.points = xyz
cloud.points -= cloud.centroid
cloud.to_file(ply_path)
print("saved shifted cloud to {}, centroid to {}".format(ply_path, txt_path))
if __name__ == '__main__':
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment