-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare.py
93 lines (62 loc) · 2.39 KB
/
prepare.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""
Author : Moshe Steyn and Travis Simmons
Date : today
Purpose: Rock the Casbah
"""
# Sample deployment
# python3 prepare.py -i /home/u24/travissimmons/cjx/season10/50_hand_label_test_2020_03_02 -o /home/u24/travissimmons/cjx/season10/gifs
# makeflow process.makeflow -j 1
import argparse
import os
import shutil
import sys
import glob
import subprocess
# --------------------------------------------------
def get_args():
"""Get command-line arguments"""
parser = argparse.ArgumentParser(
description='Rock the Casbah',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-i',
'--indir',
help='Input directory containing pointclouds',
metavar='str',
type=str,
default='')
parser.add_argument('-o',
'--outdir',
help='Output directory for gifs',
metavar='str',
type=str,
default='')
return parser.parse_args()
def main():
"""Make a jazz noise here"""
if os.path.exists('./process.makeflow'):
os.remove('./process.makeflow')
shutil.copy('./empty.makeflow', './process.makeflow')
args = get_args()
dirs = glob.glob(os.path.join(args.indir, '*'))
print(dirs)
files = [os.path.join(i, 'combined_multiway_registered.ply') for i in dirs]
print(files)
print(f'Preparing to process {len(files)} files.')
subprocess.run(['singularity', 'build', '3d_gif_generation.simg', 'docker://phytooracle/3d_segmentation_gif_generation'])
my_file = open("process.makeflow", "w")
for i in files:
if os.path.exists(i):
pcd_path = i
output_dir = args.outdir
array_path = pcd_path.replace('.ply', '.npy')
plant_name = pcd_path.split('/')[-2]
gif_path = os.path.join(output_dir, plant_name + '.gif')
procesing_format = [gif_path + ' ', ':', ' 3d_gif_generation.simg ', array_path + ' ', pcd_path, '\n\t', f'singularity run 3d_gif_generation.simg -i {pcd_path} -o {output_dir}\n\n']
my_file.writelines(procesing_format)
else:
print(i)
my_file.close()
# --------------------------------------------------
if __name__ == '__main__':
main()