-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipeline.py
executable file
·97 lines (60 loc) · 2.45 KB
/
pipeline.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
94
95
96
97
"""
Version: 1.5
Summary: Plant image traits computation pipeline
Author: suxing liu
Author-email: [email protected]
USAGE:
python pipeline.py -p /home/suxingliu/plant-image-analysis/random_test/ -ft jpg
parameter list:
ap.add_argument("-p", "--path", required = True, help = "path to image file")
ap.add_argument("-ft", "--filetype", required=True, help="Image filetype")
"""
import subprocess, os
import sys
import argparse
'''
def execute_script(cmd_line):
"""execute script inside program"""
try:
print(cmd_line)
process = subprocess.Popen(cmd_line, shell=True, stdout=subprocess.PIPE)
process.wait()
#print process.returncode
except OSError:
print("Failed ...!\n")
'''
def execute_script(cmd_line):
"""execute script inside program"""
process = subprocess.Popen(cmd_line, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# Poll process for new output until finished
while True:
nextline = str(process.stdout.readline())
if nextline == '' and process.poll() is not None:
break
sys.stdout.write(nextline)
sys.stdout.flush()
output = process.communicate()[0]
exitCode = process.returncode
if (exitCode == 0):
return output
else:
print("failed!...\n")
def image_analysis_pipeline(file_path, ext):
"""execute pipeline scripts in order"""
# step 1: segment tray image into individual plant objects
seg = "python3 color_seg.py -p " + file_path + " -ft " + str(ext)
#python /opt/code/trait_extract_parallel.py -p /home/suxingliu/plant-image-analysis/data/ -ft JPG
# step 2: compute traits for each individual plant objects in a parallel way
trait_extract_parallel = "python3 trait_extract_parallel.py -p " + file_path + " -ft " + str(ext)
print("Plant image traits computation pipeline...\n")
execute_script(trait_extract_parallel)
if __name__ == '__main__':
# construct the argument and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-p", "--path", required = True, help = "path to image file")
ap.add_argument("-ft", "--filetype", required=True, help="Image filetype")
args = vars(ap.parse_args())
# setting path to model file
file_path = args["path"]
ext = args['filetype']
image_analysis_pipeline(file_path, ext)