-
Notifications
You must be signed in to change notification settings - Fork 1
/
Run.py
61 lines (50 loc) · 1.6 KB
/
Run.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
import cv2
import GenerateFeatureVector as gfv
from numpy import genfromtxt
from knn import KNearestNeighbors
from trainSVM import SVM
import glob
import sys
#knn_obj = KNearestNeighbors()
svm_obj = SVM()
cell_length = 10
cell_width = 10
training = False
bins = 8
destination = 'Result/result'
i = 450
print(i)
for filename in sorted(glob.glob('Images/Testing/*.png')):
print(i)
sys.stdout.flush()
image = cv2.imread(filename, -1)
gfv.FeatureVectorGenerator.generate_feature_vector(image, cell_width, cell_length, training, bins, True)
test_vector = genfromtxt('new-testdata.csv', delimiter=',')
test_vector = test_vector[:, 0:26]
counter = 0
my_data = genfromtxt('new-traindata.csv', delimiter=',')
# print(my_data)
svm_obj.train(my_data)
# labels = my_data[:, 26]
# my_data = my_data[:, 0:26]
rows, columns, channels = image.shape
#print(rows)
#print(columns)
# knn_obj.train(my_data, labels, 20)
for x in range(0, rows - cell_width, cell_width):
for y in range(0, columns - cell_length, cell_length):
test = [test_vector[counter]]
# label = knn_obj.predict(test)
label = svm_obj.test(test)
# print(label)
if label == 1:
image[x:x+cell_width, y:y+cell_length, 0] = 00
image[x:x+cell_width, y:y+cell_length, 1] = 00
image[x:x+cell_width, y:y+cell_length, 2] = 100
counter += 1
#cv2.imshow('image', image)
#cv2.waitKey(0)
#cv2.destroyAllWindows()
url = destination + str(i) + '.png'
i = i+1
cv2.imwrite(url, image)