-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lane Follower Systems into dev #211
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split the code into smaller functions so that it's easier to follow. The use of einops might also be nice. I would also add type annotations to variables so that we have a better idea of how the data is getting permuted.
# Lane Follower for a single camera | ||
# Applies a perspective transform to an image, and isolates lane lines |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a component.toml
with this information.
import numpy as np | ||
import math | ||
import cv2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Imports should be sorted alphabetically and have whitespace between a standard lib imports and 3rd-party improts. They should also come before 3rd-party imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used isort
# Constants for how we process images | ||
# These should be parametrized and better defined at a later date: as part of testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Constants for how we process images | |
# These should be parametrized and better defined at a later date: as part of testing |
NWINDOWS = 9 | ||
SEARCH_WIDTH = 100 | ||
MINPIXELS = 40 | ||
LANE_POLY_SIZE = 2 | ||
|
||
# Rendering Parameters | ||
BOX_COLOR = (0, 255, 0) | ||
LANE_COLOR = (255, 0, 0) | ||
|
||
DRAW_THICKNESS = 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make a configuration dataclass so that we can easily pass them to a lane-follower. I would also give them the same defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a .toml
# Need to determine if these should remain properties | ||
# Or if they should be passed as arguments to Plot_Line | ||
@property | ||
def _binary_warped(self, value: np.ndarray): | ||
self._binary_warped = value | ||
self.histogram = np.sum( | ||
self.binary_warped[self.binary_warped.shape[0] // 2 :, :], axis=0 | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow why you're making this a property? If this is a getter, shouldn't it be a public member?
|
||
def plot_line(self): | ||
|
||
if self.binary_warped is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if self.binary_warped is None: | |
if not self.binary_warped: |
import cv2 | ||
|
||
|
||
class IndividualFollower: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class IndividualFollower: | |
class LaneFollower: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not making this change as lane follower is an overarching class that creates 2 individual followers; one for each camera.
Seriously need to reconsider structure of line_window1 & line_window2: These lines are only for rendering, but seem to be half running in the loop and half out. This doesn't make a lot of sense? I think they can be fully replaced with the resultant np.polyval
…r better readability
… full module to dev
import toml | ||
from einops import repeat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import toml | |
from einops import repeat | |
import toml | |
from einops import repeat |
from einops import repeat | ||
|
||
|
||
class ifResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow PEP8 for naming. This can also be made into a dataclass
.
def __init__(self, toml_path='Follower_Consts.toml'): | ||
|
||
self.consts = toml.load(toml_path)["Individual_Follower"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the vision, but the execution can be better. IMO TOML should be unmarshaled outside the class and passed as a constants struct.
# self.fit is set in Plot_Line | ||
self.fit = None | ||
# These two are set below | ||
self._binary_warped = None | ||
self._histogram = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these comments add much value to the reader. I'd also separate public and private members of the class.
# Need to determine if these should remain properties | ||
# Or if they should be passed as arguments to Plot_Line | ||
@property | ||
def _binary_warped(self, value: np.ndarray): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@property
should only get used for public members and without arguments so that they just act as a variable access.
) | ||
return out_img | ||
|
||
def plot_line(self) -> ifResult: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you search online how other projects might add code to generate plots for certain things? There has to be a cleaner way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code should just not be committed as it's accessible in Git history.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know we haven't discussed this yet, but here's the current schema for a component:
schema = Schema( |
{name = "Vaibhav Hariani"}, | ||
{name = "Isaiah Rivera"}, | ||
] | ||
description = "IGVC lane follower module for a single camera" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = "IGVC lane follower module for a single camera" | |
description = "lane follower for a video feed" |
Something along those lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to just have these as dataclasses
that have "sane" defaults.
Post-Comp merge of all lane follower code into dev, with atomic commits. Cleaning up systems to make them more legibile and more clear.