forked from diyjac/SDC-P5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chogtestRGB3.py
91 lines (79 loc) · 3.44 KB
/
chogtestRGB3.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
88
89
90
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import numpy as np
import cv2
import glob
import time
from sklearn.svm import LinearSVC
from sklearn.preprocessing import StandardScaler
from skimage.feature import hog
from sklearn.externals import joblib
from testlib.slidingWindows import SlidingWindows
from testlib.CHOG import CHOG
versionName = 'CHOGRGB3'
trained_model = './trained/'+versionName+'.pkl'
trained_scalar = './trained/scaler'+versionName+'.pkl'
visualfile = './visualized/'+versionName+'-augmented.jpg'
orient = 9
pix_per_cell = 8
cell_per_block = 2
# try to make thresholds LOWER!
# remove more false positives
# going down from 13.0
# going down from 12.0
# going down from 10.0
# going down from 8.0
# going up from 5.0
# going down from 6.0
# going up from 5.5
# locked
hthreshold = 5.75
# remove more false negatives
# going down from 2.0
# going down from 1.5
# going down from 1.0 <-- can see edge car and car 2 3 in test 22
# going down from 0.8 <-- can see edge car and car 1 2 3 in test 22
# going down from 0.7 <-- can see edge car and car 1 2 3 in test 22
# going down from 0.5 <-- can see edge car and car 1 2 3 in test 22 but still no 4
# going down from 0.0 <-- can see edge car and car 1 2 3 in test 22 but still no 4
# going down from -1.0 <-- can see edge car and car 1 2 3 and 4 test 22 but still no (5)
# going down from -2.0 <-- can see edge car and car 1 2 3 4 and (5) test 22
# going down from -1.5 <-- can see edge car and car 1 2 3 4 test 22
lthreshold = -1.75
svc = joblib.load(trained_model)
slide_window = SlidingWindows()
chog = CHOG(trained_scalar=trained_scalar)
outimages = []
images = glob.glob('./test_images/test*proj.jpg')
for file in images:
print("processing: ", file)
image = cv2.cvtColor(cv2.imread(file), cv2.COLOR_BGR2RGB)
print("initializing...")
windows = slide_window.completeScan(file)
foundwindows = []
print("Processing",len(windows),"windows high...")
for window in windows:
wimage = image[window[0][1]:window[1][1], window[0][0]:window[1][0]]
wfeatures = chog.extract_features(wimage, cspace='RGB', spatial_size=(32, 32),
orient=orient, pix_per_cell=pix_per_cell, cell_per_block=cell_per_block,
hist_bins=32, hist_range=(0, 256))
if wfeatures is not None:
confidence = svc.decision_function(wfeatures.reshape(1, -1))
if confidence[0] > hthreshold:
foundwindows.append(window)
window_img1 = chog.draw_boxes(image, foundwindows, color=(0, 0, 255), thick=2)
foundwindows = []
print("Processing",len(windows),"windows low...")
for window in windows:
wimage = image[window[0][1]:window[1][1], window[0][0]:window[1][0]]
wfeatures = chog.extract_features(wimage, cspace='RGB', spatial_size=(32, 32),
orient=orient, pix_per_cell=pix_per_cell, cell_per_block=cell_per_block,
hist_bins=32, hist_range=(0, 256))
if wfeatures is not None:
confidence = svc.decision_function(wfeatures.reshape(1, -1))
if confidence[0] > lthreshold:
foundwindows.append(window)
window_img2 = chog.draw_boxes(image, foundwindows, color=(0, 0, 255), thick=2)
outimages.append((file, orient, pix_per_cell, cell_per_block, window_img1, window_img2))
chog.drawPlots(visualfile, versionName, outimages, hthreshold, lthreshold)