added report

This commit is contained in:
Jeena 2013-10-15 18:50:49 +02:00
parent 44e73f6083
commit fc4dc3d3a0
3 changed files with 223 additions and 15 deletions

View file

@ -13,11 +13,8 @@ def extractFeatures(label):
img = cv2.imread(directory + fn, 0)
#temp = cv.CreateImage((100,100), cv.CV_8U, 1)
#cv.Smooth(img, temp)
# find edges
canny = cv2.Canny(img, 50, 100)
color_dst = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
# find colored
black_pixels = numpy.count_nonzero(img)
@ -30,8 +27,11 @@ def extractFeatures(label):
try:
for line in lines[0]:
x1, y1, x2, y2 = line
#cv2.line(color_dst, (x1, y1), (x2, y2), cv.RGB(255,0,0), 1, 8)
length = int(math.sqrt(math.pow((x1-x2), 2) + math.pow((y1-y2), 2)))
# Pythagoras
a2 = math.pow((x1-x2), 2)
b2 = math.pow((y1-y2), 2)
length = int(math.sqrt(a2 + b2))
lengths.append(length)
angle = int(math.degrees(math.atan((y1-y2) / (x1-x2))))
@ -44,13 +44,10 @@ def extractFeatures(label):
mid_length = sum(lengths) / lines_count
mid_angle = sum(angles) / lines_count
features.append([[lines_count, mid_length, mid_angle, black_pixels], label])
#cv2.namedWindow("Original")
#cv2.imshow("Original", img)
#cv2.namedWindow('Lines image ' + fn)
#cv2.imshow('Lines image ' + fn, color_dst)
features.append([
[lines_count, mid_length, mid_angle, black_pixels],
label
])
return features
@ -72,7 +69,8 @@ if __name__ == "__main__":
tree = KDTree(features)
for t in xrange(0, test_count * 2):
d, i = tree.query(test_features[t], k=2)
d, i = tree.query(test_features[t], k=3)
print "-"
for j in xrange(0, len(i)):
print test_labels[t] + " is predicted to be a " + labels[i[j]] + " j: " + str(i[j]) + " d: " + str(d[j])
print test_labels[t] + " is predicted to be a " + labels[i[j]]