-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunko.py
87 lines (78 loc) · 2.9 KB
/
unko.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import vdtools
import numpy as np
import pickle
import cv2
import glob
import matplotlib.image as mpimg
def generate_window_cppcode():
windows_list = pickle.load( open( "./cache/windows_list.p", "rb" ) )
print("{")
for window in windows_list:
print("{{", window[0][1] ,",", window[1][1], "},{", window[0][0], ",", window[1][0], "}},")
print("};")
def generate_window_candidate():
windows_list = pickle.load( open( "./cache/windows_list.p", "rb" ) )
# image = cv2.imread('./image_0133.png')
image = cv2.imread('./video/outtest4/image_0220.png')
for i, window in enumerate(windows_list):
crop = image[window[0][1]: window[1][1], window[0][0]:window[1][0]]
name = 'crop_test2/crop/image' + str(i) + '.png'
cv2.imwrite(name, crop)
imcopy = np.copy(image)
cv2.rectangle(imcopy, window[0], window[1], (0, 0, 255), 3)
cv2.imwrite('crop_test2/window/image' + str(i) + '.png', imcopy)
def test_one_resized_image():
image_paths = glob.glob('./data/red/*')
finder = vdtools.WindowFinder()
# print(image_paths)
# path = image_paths[0]
# for path in image_paths:
path = 'resized87.png'
# test_img = mpimg.imread(path)#cv2.imread(path)
test_img = cv2.imread(path)
clf = pickle.load( open( "./cache/clf.p", "rb" ))
scaler = pickle.load(open( "./cache/scaler.p", "rb"))
features = finder.singleimgfeatures(test_img)
# for i in range(len(features)):
# print(features[i])
test_features = scaler.transform(np.array(features).reshape(1, -1))
# print(test_features.shape)
preds = clf.predict_proba(test_features)[:,1]
print(path, preds)
def test_one_image():
pass
def show_importances():
clf = pickle.load( open( "./cache/clf.p", "rb" ))
importances = clf.feature_importances_
# print(importances)
spatial_hsv = importances[0:192]
spatial_rgb = importances[192:384]
hist_hsv = importances[384:384+36]
hist_rgb = importances[384+36:384+72]
hog = importances[384+72:]
print('spatial_hsv', np.sum(np.array(spatial_hsv)))
print('spatial_rgb', np.sum(np.array(spatial_rgb)))
print('hist_hsv', np.sum(np.array(hist_hsv)))
print('hist_rgb', np.sum(np.array(hist_rgb)))
print('hog', np.sum(np.array(hog)))
def scaler_test():
path = 'resized87.png'
finder = vdtools.WindowFinder()
test_img = cv2.imread(path)
clf = pickle.load( open( "./cache/clf.p", "rb" ))
scaler = pickle.load(open( "./cache/scaler.p", "rb"))
scaler_mean = pickle.load(open( "./cache/scaler_mean.p", "rb" ))
scaler_std = pickle.load(open( "./cache/scaler_std.p", "rb" ))
features = finder.singleimgfeatures(test_img)
transformed = scaler.transform(np.array(features).reshape(1, -1))[0]
my_transformed = (np.array(features) - scaler_mean) / (scaler_std + 1e-8)
for i in range(744):
if(abs(transformed[i] - my_transformed[i]) > 1e-4):
print("transform failed")
print("transform check complete")
# test_one_resized_image()
show_importances()
# scaler_test()
# generate_window_candidate()
# generate_window_cppcode()
# unko = vdtools.WindowFinder()