-
Notifications
You must be signed in to change notification settings - Fork 1
/
hogX.py
46 lines (35 loc) · 853 Bytes
/
hogX.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
import csv
import cv2
from random import randint
import numpy as np
import os
from sklearn import svm
X1 = []
y1=[]
loc=[]
hog = cv2.HOGDescriptor()
with open('matrix.txt', 'rb') as csvfile:
matrixreader = csv.reader(csvfile, delimiter=' ')
for row in matrixreader:
X1.append(row)
print "done"
with open("ylist.txt", 'r') as my_file:
reader = csv.reader(my_file, delimiter='\t')
y1 = list(reader)
#print(my_list)
print "done"
with open("loclist.txt", 'r') as my_file:
reader = csv.reader(my_file, delimiter='\t')
loc = list(reader)
#print(my_list)
print "done"
clf=svm.LinearSVC()
clf.fit(X1,y1)
print "done"
x2=cv2.imread("1.jpg")
img_scaled = cv2.resize(x2, (250, 200), interpolation=cv2.INTER_AREA)
h = hog.compute(img_scaled)
x2=np.hstack(h)
x2=x2.transpose()
ans=clf.predict(x2)
print loc[ans[0]]