-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfinal_test_v4.py
70 lines (52 loc) · 2.02 KB
/
final_test_v4.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
# Version 4
# command: $ python final_test_v[x] [partition number] [number of partitions]
import os
import sys
import glob
import multiprocessing
##Worker used to submit to differenct cores of
def worker(ctrl, name):
"""Worker function"""
# print ctrl
error_code = os.system(ctrl)
if (error_code <> 0):
raiseException("ERROR: SIFT didn't run correctly on " + name)
print "Terminating process"
sys.exit(1)
return
t = 0
n = 1
if len(sys.argv) > 1:
t = int(sys.argv[1])
if len(sys.argv) > 2:
n = int(sys.argv[2])
path_in = './slide_img/' # where the home images are
path_out = './slide_img_out/' #where we want the output to go
num_files = len(glob.glob1(path_in,'*.pgm')) #number of file of type
num_in_div = num_files/n #number of file per division
if num_in_div == 0: #catch if num_in_div == 0
num_in_div = num_files + 1
re_in_div = num_files%n #number of remainder
start_val = t * num_in_div #calc start position of array
if (start_val + num_in_div) <= num_files:
end_val = start_val + num_in_div #if will not go out of bounds
else:
end_val = start_val + re_in_div #if iteration will hit upper limit
print end_val
img_names = glob.glob1(path_in,'*.pgm')[start_val:end_val] #tells up what the names of each file we are using stored as an array
img_count = len(img_names) #tells us how many images there are
#print "%02d" % (t) used for debug
if __name__ == '__main__':
jobs = []
for i in range(0,img_count):
key_file = path_out + img_names[i].replace('.pgm','') +'.vl'
cmd = '~/vlfeat-0.9.17/bin/glnxa64/sift' + " " + './slide_img/' + img_names[i] + " -o " + key_file
p = multiprocessing.Process(target=worker, args=(cmd, img_names[i]))
jobs.append(p)
p.start()
# v4 added multiprocessing to access multiple cores
# ToDo: Make sure don't overload system with workers
# v3 updated system to take specify which numeric files for better compatablility with
# distributed systems
# v2 updated program so that all files of given type can be read in for use
# v1 program tested working