@@ -36,9 +36,12 @@ def _binary_warped(self, value: np.ndarray):
36
36
self .binary_warped [self .binary_warped .shape [0 ] // 2 :, :], axis = 0
37
37
)
38
38
39
- def get_white_pixels (self , window , window_height , out_img = None ):
39
+ def get_white_pixels (self ):
40
+ # Returns an output image
40
41
NWINDOWS = self .consts ["NWINDOWS" ]
41
42
SEARCH_WIDTH = self .consts ['SEARCH_WIDTH' ]
43
+
44
+ window_height = np .int32 (self ._binary_warped .shape [0 ] / NWINDOWS )
42
45
lane_inds = []
43
46
44
47
nonzero_pixels = self ._binary_warped .nonzero ()
@@ -48,59 +51,6 @@ def get_white_pixels(self, window, window_height, out_img=None):
48
51
empty_windows = 0
49
52
lane_base = np .argmax (self .histogram [:])
50
53
51
- for window in range (NWINDOWS ):
52
- window_dims = window * window_height
53
- win_y_upper = self ._binary_warped .shape [0 ] - window_dims
54
- # One window height lower than win_y_higher
55
- win_y_lower = win_y_upper - window_height
56
- win_x_lower = lane_base - SEARCH_WIDTH
57
- win_x_upper = lane_base + SEARCH_WIDTH
58
-
59
- lower_coords = (win_x_lower , win_y_lower )
60
- upper_coords = (win_x_upper , win_y_lower )
61
- cv2 .rectangle (
62
- out_img ,
63
- lower_coords ,
64
- upper_coords ,
65
- self .consts ["BOX_COLOR" ],
66
- self .consts ["DRAW_THICKNESS" ],
67
- )
68
-
69
- white_pix_inds = (
70
- (nonzero_y >= win_y_lower )
71
- & (nonzero_y < win_y_upper )
72
- & (nonzero_x >= win_x_lower )
73
- & (nonzero_x >= win_x_upper )
74
- ).nonzero_pixels ()[0 ]
75
-
76
- # This should likely be moved into the if statement: leaving for now
77
- lane_inds .append (white_pix_inds )
78
- if len (white_pix_inds ) > self .consts ["MINPIXELS" ]:
79
- # np.mean will return a float: We need an exact value
80
- lane_base = np .int32 (np .mean (nonzero_x [white_pix_inds ]))
81
- else :
82
- empty_windows += 1
83
-
84
- # if len(lane_inds) == 0:
85
- # return result
86
-
87
- lane_array = np .concatenate (lane_inds )
88
- lane_x_pos = nonzero_x [lane_array ]
89
- lane_y_pos = nonzero_y [lane_array ]
90
- # TODO: test if this statement is necessary
91
- if lane_x_pos .any () and lane_y_pos .any ():
92
- self ._fit = np .polyfit (
93
- lane_y_pos , lane_x_pos , self .consts ["LANE_POLY_SIZE" ]
94
- )
95
-
96
- out_img [nonzero_y [lane_array ], nonzero_x [lane_array ]] = (
97
- self .consts ["LANE_COLOR" ]
98
- )
99
-
100
- def plot_line (self ) -> ifResult :
101
- if not self ._binary_warped :
102
- raise Exception ("no binary warp specified" )
103
-
104
54
# Image to visualize output
105
55
out_img = repeat (self ._binary_warped , 'h w -> h w c' , repeat = 3 ) * 255
106
56
##These outputs need to be confirmed compatible
@@ -111,22 +61,6 @@ def plot_line(self) -> ifResult:
111
61
# * 255
112
62
# )
113
63
114
- NWINDOWS = self .consts ['NWINDOWS' ]
115
-
116
- window_height = np .int32 (self ._binary_warped .shape [0 ] / NWINDOWS )
117
- ##Create result class:
118
- result = ifResult ()
119
-
120
- lane_inds = []
121
-
122
- nonzero_pixels = self ._binary_warped .nonzero ()
123
- nonzero_y = np .array (nonzero_pixels [0 ])
124
- nonzero_x = np .array (nonzero_pixels [1 ])
125
-
126
- empty_windows = 0
127
- lane_base = np .argmax (self .histogram [:])
128
-
129
- SEARCH_WIDTH = self .consts ['SEARCH_WIDTH' ]
130
64
for window in range (NWINDOWS ):
131
65
window_dims = window * window_height
132
66
win_y_upper = self ._binary_warped .shape [0 ] - window_dims
@@ -159,10 +93,8 @@ def plot_line(self) -> ifResult:
159
93
lane_base = np .int32 (np .mean (nonzero_x [white_pix_inds ]))
160
94
else :
161
95
empty_windows += 1
162
-
163
96
if len (lane_inds ) == 0 :
164
- return result
165
-
97
+ return None
166
98
lane_array = np .concatenate (lane_inds )
167
99
lane_x_pos = nonzero_x [lane_array ]
168
100
lane_y_pos = nonzero_y [lane_array ]
@@ -175,17 +107,27 @@ def plot_line(self) -> ifResult:
175
107
out_img [nonzero_y [lane_array ], nonzero_x [lane_array ]] = (
176
108
self .consts ["LANE_COLOR" ]
177
109
)
110
+ return out_img
111
+
112
+ def plot_line (self ) -> ifResult :
113
+ if not self ._binary_warped :
114
+ raise Exception ("no binary warp specified" )
115
+
116
+ result = ifResult ()
117
+
118
+ NWINDOWS = self .consts ["NWINDOWS" ]
119
+ window_height = np .int32 (self ._binary_warped .shape [0 ] / NWINDOWS )
120
+ out_img = self .get_white_pixels ()
121
+ if out_img is None :
122
+ return result
178
123
179
124
##Generates the search window area
180
125
window_img = np .zeros_like (out_img )
181
-
182
126
# Create linearly spaced points at each height, evaluate polynomial, create coordinates
183
127
x_val = np .arange (0 , window_height , step = 5 ).T
184
128
y_val = np .polyval (self .fit , x_val )
185
129
coords = np .concatenate ((x_val , y_val ), axis = 0 )
186
-
187
130
##TODO: Test if this approach works
188
-
189
131
cv2 .polylines (
190
132
out_img ,
191
133
coords ,
0 commit comments