forked from sightmachine/SimpleCV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_multi.py
More file actions
65 lines (60 loc) · 1.98 KB
/
Copy pathtest_multi.py
File metadata and controls
65 lines (60 loc) · 1.98 KB
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
from SimpleCV import *
import string
import pickle
color = Color()
subset = 5
iset = ImageSet()
iset.load("./dataset/model/",sort_by="name")
iset = iset[0:subset]
testset = ImageSet()
testset.load("./dataset/test/",sort_by="name")
testset = testset[0:subset]
# fix featureset standardize to include fname
#iset = iset.standardize(400,400) # this should deal with some of the point issues
#testset = testset.standardize(400,400)
names = []
for i in iset:
names.append(i.filename)
print names
names = names[0:subset]
scc = None
fname = 'classifier.pkl'
load_from_file = False
if( load_from_file ):
scc = pickle.load( open( fname, "rb" ) )
else:
scc = ShapeContextClassifier(iset,names) #this needs to be pickled.
pickle.dump(scc, open( fname, "wb" ) )
print "--------------------------"
print "--------------------------"
print "Performing Analysis!"
print "--------------------------"
print "--------------------------"
classifications = []
i = 0
for test in testset:
print "--------------------------"
best, value, result = scc.classify(test)
print "Total points in result " + str(len(scc.ptMap[best]))
print "Testing: " + test.filename
print "Best Result: " + best
words = string.split(best,'/')
words2 = string.split(test.filename,'/')
test = test.resize(h=400)
true_match = iset[i].resize(h=400)
# test image, actual match, truth match
test2 = scc.imgMap[best].resize(h=400)
matchImg = test.sideBySide(test2)
matchImg = matchImg.sideBySide(true_match)
matchImg = matchImg.resize(w=1200)
label = "Matched " + words2[-1] + " with " + words[-1]
matchImg.drawText(label,10,10,color=Color.RED,fontsize=30)
label = "MatchVal: " + str(np.around(value,4))
matchImg.drawText(label,10,45,color=Color.RED,fontsize=30)
matchImg.show()
fname = "match"+str(i)+".png"
i = i + 1
matchImg.save(fname)
classifications.append((test.filename,result))
print result
pickle.dump(classifications, open( "classifications.pkl", "wb" ) )