Skip to content
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

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

Vaibhav-Hariani
Copy link
Contributor

Post-Comp merge of all lane follower code into dev, with atomic commits. Cleaning up systems to make them more legibile and more clear.

@Vaibhav-Hariani Vaibhav-Hariani self-assigned this Sep 16, 2024
Copy link
Member

@jacobkoziej jacobkoziej left a 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.

Comment on lines 1 to 2
# Lane Follower for a single camera
# Applies a perspective transform to an image, and isolates lane lines
Copy link
Member

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.

Comment on lines 3 to 5
import numpy as np
import math
import cv2
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used isort

Comment on lines 9 to 10
# Constants for how we process images
# These should be parametrized and better defined at a later date: as part of testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Constants for how we process images
# These should be parametrized and better defined at a later date: as part of testing

Comment on lines 11 to 20
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
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a .toml

Comment on lines 29 to 36
# 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
)
Copy link
Member

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.binary_warped is None:
if not self.binary_warped:

components/lane_follower/src/individual_follower.py Outdated Show resolved Hide resolved
components/lane_follower/src/individual_follower.py Outdated Show resolved Hide resolved
components/lane_follower/src/individual_follower.py Outdated Show resolved Hide resolved
import cv2


class IndividualFollower:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class IndividualFollower:
class LaneFollower:

Copy link
Contributor Author

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.

Comment on lines +5 to +6
import toml
from einops import repeat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import toml
from einops import repeat
import toml
from einops import repeat

from einops import repeat


class ifResult:
Copy link
Member

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.

Comment on lines +21 to +23
def __init__(self, toml_path='Follower_Consts.toml'):

self.consts = toml.load(toml_path)["Individual_Follower"]
Copy link
Member

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.

Comment on lines +24 to +28
# self.fit is set in Plot_Line
self.fit = None
# These two are set below
self._binary_warped = None
self._histogram = None
Copy link
Member

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.

Comment on lines +30 to +33
# 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):
Copy link
Member

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:
Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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:

{name = "Vaibhav Hariani"},
{name = "Isaiah Rivera"},
]
description = "IGVC lane follower module for a single camera"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "IGVC lane follower module for a single camera"
description = "lane follower for a video feed"

Something along those lines.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants