forked from diyjac/SDC-P5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chogtestRGB2.py
90 lines (78 loc) · 3.49 KB
/
chogtestRGB2.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
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 = 'CHOGRGB2'
trained_model = './trained/'+versionName+'.pkl'
trained_scalar = './trained/scaler'+versionName+'.pkl'
visualfile = './visualized/'+versionName+'-augmented.jpg'
orient = 8
pix_per_cell = 4
cell_per_block = 2
# try to make thresholds LOWER!
# remove more false positives
# going down from 8.5
# going up from 7.0
# going up from 7.75
# going up from 8.15
# going up from 8.25
# locked
hthreshold = 8.35
# remove more false negatives
# going down from 3.0
# going down from 2.5
# going down from 2.0 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from 1.5 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from 1.0 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from 0.8 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from 0.5 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from 0.0 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going down from -1.0 <-- cannot see edge car, but can see 3 and 4 car in test 22.
# going up from -5.0 <-- can see edge car, car 2 3 4 (5)
# locked - at -2.0, can see edge car, car 3 4 (5) in test 22.
lthreshold = -2.0
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)