align_frames_with_lidar.py 1.29 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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()