yaraa11 commited on
Commit
14d5072
·
verified ·
1 Parent(s): c8e4ccb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +45 -7
README.md CHANGED
@@ -145,15 +145,53 @@ import tensorflow as tf
145
  import cv2
146
  import numpy as np
147
 
148
- model = tf.keras.models.load_model("model_path", compile=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
- img = cv2.imread("road.jpg")
151
- img = cv2.resize(img, (INPUT_W, INPUT_H))
152
- img = img / 255.0
153
- img = np.expand_dims(img, axis=0)
154
 
155
- pred = model.predict(img)
156
- mask = np.argmax(pred[0], axis=-1)
157
  ```
158
 
159
  For full pipelines including video processing and lane visualization,
 
145
  import cv2
146
  import numpy as np
147
 
148
+ # -------- Load model --------
149
+ model = tf.keras.models.load_model(
150
+ "model_path",
151
+ compile=False
152
+ )
153
+
154
+ # -------- Load & preprocess image --------
155
+ img_path = "image_path"
156
+
157
+ orig = cv2.imread(img_path)
158
+ orig = cv2.cvtColor(orig, cv2.COLOR_BGR2RGB)
159
+
160
+ img = cv2.resize(orig, (256, 256))
161
+ img_norm = img / 255.0
162
+ img_input = np.expand_dims(img_norm, axis=0)
163
+
164
+ # -------- Predict --------
165
+ pred = model.predict(img_input)
166
+ mask = np.argmax(pred[0], axis=-1) # (256, 256)
167
+
168
+ # -------- Create color mask --------
169
+ # Class mapping:
170
+ # 0 = background, 1 = road, 2 = lane
171
+
172
+ color_mask = np.zeros((256, 256, 3), dtype=np.uint8)
173
+
174
+ color_mask[mask == 1] = (255, 0, 0) # Road -> Red
175
+ color_mask[mask == 2] = (0, 255, 0) # Lane -> Green
176
+
177
+ # -------- Overlay full segmentation --------
178
+ overlay_full = cv2.addWeighted(img.astype(np.uint8), 0.6, color_mask, 0.4, 0)
179
+
180
+ # -------- Lane-only overlay --------
181
+ lane_mask = np.zeros_like(color_mask)
182
+ lane_mask[mask == 2] = (0, 255, 0)
183
+
184
+ overlay_lane = cv2.addWeighted(img.astype(np.uint8), 0.7, lane_mask, 0.3, 0)
185
+
186
+ # -------- Show results --------
187
+ cv2.imshow("Original", cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2BGR))
188
+ cv2.imshow("Segmentation Overlay (Road + Lane)", cv2.cvtColor(overlay_full, cv2.COLOR_RGB2BGR))
189
+ cv2.imshow("Lane Only Overlay", cv2.cvtColor(overlay_lane, cv2.COLOR_RGB2BGR))
190
+
191
+ cv2.waitKey(0)
192
+ cv2.destroyAllWindows()
193
 
 
 
 
 
194
 
 
 
195
  ```
196
 
197
  For full pipelines including video processing and lane visualization,