kr4phy commited on
Commit
2c5dee6
·
1 Parent(s): 3e4fcd4

Enhance lane drawing functionality with filled lane area and improved color coding

Browse files
Files changed (1) hide show
  1. lane_detection.py +23 -4
lane_detection.py CHANGED
@@ -18,7 +18,9 @@ def region_of_interest(img, vertices):
18
 
19
  def draw_lines(img, lines, color=[0, 255, 0], thickness=3):
20
  """
21
- Draw lines on the image.
 
 
22
  """
23
  if lines is None:
24
  return img
@@ -69,13 +71,30 @@ def draw_lines(img, lines, color=[0, 255, 0], thickness=3):
69
  left_line = average_lines(left_lines, img.shape)
70
  right_line = average_lines(right_lines, img.shape)
71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  if left_line is not None:
73
- cv2.line(line_img, (left_line[0], left_line[1]), (left_line[2], left_line[3]), color, thickness)
 
74
 
75
  if right_line is not None:
76
- cv2.line(line_img, (right_line[0], right_line[1]), (right_line[2], right_line[3]), color, thickness)
 
77
 
78
- return cv2.addWeighted(img, 1.0, line_img, 1.0, 0)
 
79
 
80
 
81
  def process_frame(frame):
 
18
 
19
  def draw_lines(img, lines, color=[0, 255, 0], thickness=3):
20
  """
21
+ Draw lines on the image with filled lane area.
22
+ - Lane lines: Red color
23
+ - Lane interior: Green semi-transparent fill
24
  """
25
  if lines is None:
26
  return img
 
71
  left_line = average_lines(left_lines, img.shape)
72
  right_line = average_lines(right_lines, img.shape)
73
 
74
+ # Fill the lane area with green color
75
+ if left_line is not None and right_line is not None:
76
+ # Create polygon points for the lane area
77
+ lane_polygon = np.array([[
78
+ (left_line[0], left_line[1]), # Left bottom
79
+ (left_line[2], left_line[3]), # Left top
80
+ (right_line[2], right_line[3]), # Right top
81
+ (right_line[0], right_line[1]) # Right bottom
82
+ ]], dtype=np.int32)
83
+
84
+ # Fill the lane area with green (semi-transparent)
85
+ cv2.fillPoly(line_img, lane_polygon, (0, 255, 0))
86
+
87
+ # Draw the lane lines in red with thicker lines
88
  if left_line is not None:
89
+ cv2.line(line_img, (left_line[0], left_line[1]), (left_line[2], left_line[3]),
90
+ (0, 0, 255), thickness * 2) # Red color (BGR format)
91
 
92
  if right_line is not None:
93
+ cv2.line(line_img, (right_line[0], right_line[1]), (right_line[2], right_line[3]),
94
+ (0, 0, 255), thickness * 2) # Red color (BGR format)
95
 
96
+ # Blend with original image (make the overlay semi-transparent)
97
+ return cv2.addWeighted(img, 0.8, line_img, 0.5, 0)
98
 
99
 
100
  def process_frame(frame):