-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lane detection sliding windows (#35)
* commit * implemented lane detection by using a n-sliding window algorithm. next to the implementation of the sliding window algorithm i also did the following things: - moved images to resource folder - implemented tests/benchmark for line detection - adjusted gamma of the image stitching - fixed some formatting * fixed test * fixed comments
- Loading branch information
1 parent
af47d45
commit 4167f43
Showing
55 changed files
with
1,067 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
from common.constants import SpeedMode | ||
|
||
speed_mode: SpeedMode = SpeedMode.SLOW | ||
speed_mode_to_speed = { | ||
SpeedMode.SLOW: 25, | ||
SpeedMode.MEDIUM: 50, | ||
SpeedMode.FAST: 75, | ||
SpeedMode.VERY_FAST: 100 | ||
} | ||
speed_mode_to_speed = {SpeedMode.SLOW: 25, SpeedMode.MEDIUM: 50, SpeedMode.FAST: 75, SpeedMode.VERY_FAST: 100} | ||
|
||
speed = speed_mode_to_speed[speed_mode] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
from src.utils.image import cut_image | ||
|
||
|
||
def topdown(image: np.ndarray) -> np.ndarray: | ||
"""Transform stitched image to top-down view.""" | ||
if image is None: | ||
raise ValueError("Error: Unable to load image") | ||
|
||
pts = np.array([[55, 900], [1841, 253], [2067, 253], [3861, 900]], dtype=np.float32) | ||
ipm_pts = np.array([[780, 450], [800, 1100], [600, 1100], [620, 450]], dtype=np.float32) | ||
ipm_matrix = cv2.getPerspectiveTransform(pts, ipm_pts) | ||
ipm = cv2.warpPerspective(image, ipm_matrix, (image.shape[1], image.shape[0]), flags=cv2.INTER_LINEAR) | ||
ipm = cut_image(ipm, 300, 450, 800, 900) | ||
ipm = cv2.rotate(ipm, cv2.ROTATE_90_CLOCKWISE) | ||
return cv2.rotate(ipm, cv2.ROTATE_90_CLOCKWISE) | ||
|
||
|
||
if __name__ == "__main__": | ||
# load stitched image | ||
image = cv2.imread("result.jpg") | ||
|
||
# time the topdown function and print the Iterations per second | ||
import time | ||
|
||
start = time.time() | ||
for _ in range(500): | ||
topdown(image) | ||
end = time.time() | ||
fps = 500 / (end - start) | ||
|
||
# convert to grayscale | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
|
||
# time again | ||
start = time.time() | ||
for _ in range(500): | ||
topdown(gray) | ||
end = time.time() | ||
fps_gray = 500 / (end - start) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import cv2 | ||
import numpy as np | ||
|
||
from lane_assist.image_manipulation.top_down_transfrom import topdown | ||
from lane_assist.line_detection.line import Line, LineType | ||
from lane_assist.line_detection.window import Window | ||
from lane_assist.line_detection.window_search import window_search | ||
from src.utils.image import list_images | ||
|
||
|
||
def get_lines(image: np.ndarray) -> list[Line]: | ||
"""Get the lines in the image. | ||
This function will take an image and return the lines in the image. | ||
the image shoulb be stitched and not top down | ||
""" | ||
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
top_down = topdown(gray) | ||
white = cv2.inRange(top_down, 200, 255) | ||
blurred = cv2.GaussianBlur(white, (15, 15), 0) | ||
return window_search(blurred, 50) | ||
|
||
|
||
def main() -> None: | ||
"""Example usage of the line detection. | ||
this function is used for testing the line detection algorithm. | ||
this is done by taking a few images and drawing the lines on the topdown image. | ||
""" | ||
test_images = [ | ||
cv2.imread("../../../tests/line_detection/images/corner.jpg"), | ||
cv2.imread("../../../tests/line_detection/images/straight.jpg"), | ||
cv2.imread("../../../tests/line_detection/images/crossing.jpg"), | ||
cv2.imread("../../../tests/line_detection/images/stopline.jpg"), | ||
] | ||
|
||
|
||
colours = { | ||
LineType.SOLID: (255, 0, 0), # red | ||
LineType.DASHED: (0, 255, 0), # green | ||
LineType.STOP: (0, 0, 255), # blue | ||
} | ||
|
||
final_images = [] | ||
# convert the images, so we can find the lines | ||
for img in test_images: | ||
lines = get_lines(img) | ||
td_img = topdown(img) # convert too topdown to draw the lines | ||
|
||
# draw the points on the topdown image | ||
for line in lines: | ||
for point in line.points: | ||
colour = colours[line.line_type] | ||
cv2.circle(td_img, (point[0], point[1]), 10, colour, -1) | ||
|
||
final_images.append(td_img) | ||
|
||
list_images(final_images, rows=4, cols=2) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.