-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
58 lines (52 loc) · 1.48 KB
/
predict.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
from sklearn import svm
from sklearn.externals import joblib
import cv2
import numpy as np
import os
import math
np.set_printoptions(threshold=np.inf)
def isvalid(img,i,j):
if(i<0 or j<0 or i>=img.shape[0] or j>=img.shape[1]):
return 0
return 1
def HOG(img):
winSize=(64,64)
blockSize=(16,16)
blockStride=(8,8)
cellSize=(8,8)
nbins=9
derivAperture = 1
winSigma = 4.
histogramNormType = 0
L2HysThreshold = 2.0000000000000001e-01
gammaCorrection = 0
nlevels = 64
hog=cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
return hog.compute(img)
model=joblib.load('saved_svm.pkl')
test=cv2.imread('./dataset_old/images/00040.ppm')#dataset/03/00011.ppm')
print 'testing'
print test.shape
d = 0
# test=ROI(test)
out=np.zeros((test.shape),np.uint8)
for i in range(0,test.shape[0]):
for j in range(0,test.shape[1]):
out[i,j]=test[i,j]
for i in range(0,test.shape[0],10):
for j in range(0,test.shape[1],10):
if(isvalid(test,i+64,j+64)==0):
continue
if(i%100==0 and j%100==0):
print i,j
patch=test[[k for k in range(i,i+64)],:,:]
patch=patch[:,[k for k in range(j,j+64)],:]
if(model.predict(np.reshape(HOG(patch),(-1,1764)))==[1]):
P1=(j,i)
P4=(j+64,i+64)
cv2.rectangle(out,P1,P4,[0,0,255],thickness=1)
#cv2.imshow("box", out[i:i+64, j:j+64, :]); cv2.waitKey(0);
# cv2.imwrite("detected"+str(d)+".png", out[i:i+64, j:j+64, :])
d=d+1
cv2.imshow("out",out)
cv2.waitKey(0)