align_frames_with_lidar.py 1.54 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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')
Clément Pinard's avatar
Clément Pinard committed
14
parser.add_argument('--centroid_path', default=None)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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)
    if args.centroid_path is not None:
        centroid = np.loadtxt(args.centroid_path)
    else:
        centroid = np.zeros(3)

    proj = Proj(args.system)
    result = []
Clément Pinard's avatar
Clément Pinard committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
    folders = [root] + list(root.walkdirs())
    file_exts = ['jpg', 'JPG']

    for folder in tqdm(folders):

        current_folder = root.relpathto(folder)
        images = sum((folder.files('*{}'.format(ext)) for ext in file_exts), [])
        for img in 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(current_folder/img.basename(), *pos))
44
45
46
47
48
49
50

    with open(args.output, 'w') as f:
        f.writelines(result)


if __name__ == '__main__':
    main()