forked from casawa/Automatic-Stop-Sign-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify.py
50 lines (39 loc) · 1.29 KB
/
classify.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
"""
Performs the classification for an entirely new image by segmenting it and seeing if any of the segments are stop signs.
"""
import sys, os
import train, util
import segment_util as seg_util
SEGMENTS_PATH = "RESULTS"
def main():
path = ""
image_name = ""
if len(sys.argv) > 1:
path = sys.argv[1]
if not os.path.exists(path):
print "The path provided does not exist."
return
directories = path.split('/')
file_name = directories[len(directories) - 1]
else:
print "Please supply a path to an image."
return
os.system("python segment.py " + path)
segments = []
for f in os.listdir(SEGMENTS_PATH):
if 'temp' in f and image_name in f: # Ways to identify segments of the given path
segments.append(os.path.join(SEGMENTS_PATH,f))
f = open('weights.out') # Read in weights
weights = eval(f.readline())
stop_sign_flag = False
for segment in segments:
score = util.dotProduct(weights,seg_util.segmentFeatureExtractor(segment))
if score >= 0: # Stop sign found
stop_sign_flag = True
break
if stop_sign_flag:
print "Stop sign detected!"
else:
print "No stop sign detected"
if __name__ == "__main__":
main()