Lane and Object Detection
Using OpenCV and YOLOv7
Loading...
Searching...
No Matches
LaneAndObjectDetection::LaneDetector Class Reference

Detects the lane the vehicle is in and other lane-related metrics. More...

#include "LaneDetector.hpp"

Classes

class  RollingAverage
 Calculates a rolling average to provide a smoothed view of state trends over time. This class is in the private scope as the implementation is LaneDetector-specific. More...

Public Member Functions

 LaneDetector ()
 Construct a new LaneDetector object.
void RunLaneDetector (const cv::Mat &p_frame, const ObjectDetectionInformation &p_objectDetectionInformation, const bool &p_debugMode)
 Runs the lane detector against p_frame.
LaneDetectionInformation GetInformation ()
 Get the LaneDetectionInformation struct.

Private Member Functions

void AnalyseHoughLines (const std::vector< cv::Vec4i > &p_houghLines, const ObjectDetectionInformation &p_objectDetectionInformation, const bool &p_debugMode)
 Determines whether the detected hough lines are left, middle or right lane lines. The majority of the noise removal occurs here.
void UpdateLineTypes ()
 Determines whether the left, middle, and right lane lines detected are solid, dashed or empty.
void UpdateDrivingState ()
 Determines the current driving state depending upon the absence/presence of left, right and middle lane lines.
void ExecuteDrivingState ()
 Execute logic based on the current driving state.
void CalculateLanePosition ()
 Determines the lane overlay for the current lane.
void CalculateChangingLanesTurningDirection ()
 Determines the direction (left, right or neither) that the vehicle is turning while changing lanes.

Static Private Member Functions

static bool IsLineWithinObjectBoundingBoxes (const cv::Vec4i &p_houghLine, const ObjectDetectionInformation &p_objectDetectionInformation)
 Determines whether p_houghLine is within any one of the p_objectDetectionInformation object bounding boxes.

Private Attributes

LaneDetectionInformation m_laneDetectionInformation
 The LaneDetectionInformation struct containing all lane detection-related information.
RollingAverage< Globals::DrivingStatem_drivingStateRollingAverage
 The rolling average to determine the driving state.
Globals::DrivingState m_currentDrivingState
 The current driving state.
double m_changingLanesPreviousDistanceDifference
 The distance difference that will be compared to in order to determine the direction the vehicle is moving while changing lanes.
uint32_t m_changingLanesFrameCount
 The number of frames passed since a distance difference was calculated while the vehicle is changing lanes.
bool m_changingLanesFirstFrame
 Whether the current frame is the frame in which the driving state changed to CHANGING_LANES.
std::vector< cv::Vec4i > m_leftLaneLines
 The left, middle and right lane lines that have been detected for the current frame.
std::vector< cv::Vec4i > m_middleLaneLines
 The left, middle and right lane lines that have been detected for the current frame.
std::vector< cv::Vec4i > m_rightLaneLines
 The left, middle and right lane lines that have been detected for the current frame.
double m_leftLineAverageLength
 The average left, middle and right lane line lengths for the current frame.
double m_middleLineAverageLength
 The average left, middle and right lane line lengths for the current frame.
double m_rightLineAverageLength
 The average left, middle and right lane line lengths for the current frame.

Detailed Description

Detects the lane the vehicle is in and other lane-related metrics.

Definition at line 23 of file LaneDetector.hpp.

Constructor & Destructor Documentation

◆ LaneDetector()

LaneAndObjectDetection::LaneDetector::LaneDetector ( )
explicit

Construct a new LaneDetector object.

Definition at line 24 of file LaneDetector.cpp.

Member Function Documentation

◆ RunLaneDetector()

void LaneAndObjectDetection::LaneDetector::RunLaneDetector ( const cv::Mat & p_frame,
const ObjectDetectionInformation & p_objectDetectionInformation,
const bool & p_debugMode )

Runs the lane detector against p_frame.

Parameters
p_frameThe frame to run the lane detector against.
p_objectDetectionInformationThe ObjectDetectionInformation struct containing all object detection-related information.
p_debugModeWhether in debug mode.

Definition at line 34 of file LaneDetector.cpp.

◆ GetInformation()

LaneDetectionInformation LaneAndObjectDetection::LaneDetector::GetInformation ( )

Get the LaneDetectionInformation struct.

Returns
LaneDetectionInformation The LaneDetectionInformation struct.

Definition at line 70 of file LaneDetector.cpp.

◆ AnalyseHoughLines()

void LaneAndObjectDetection::LaneDetector::AnalyseHoughLines ( const std::vector< cv::Vec4i > & p_houghLines,
const ObjectDetectionInformation & p_objectDetectionInformation,
const bool & p_debugMode )
private

Determines whether the detected hough lines are left, middle or right lane lines. The majority of the noise removal occurs here.

Parameters
p_houghLinesThe hough lines that have been detected.
p_objectDetectionInformationThe ObjectDetectionInformation struct containing the object bounding boxes.
p_debugModeWhether in debug mode.

Definition at line 108 of file LaneDetector.cpp.

◆ IsLineWithinObjectBoundingBoxes()

bool LaneAndObjectDetection::LaneDetector::IsLineWithinObjectBoundingBoxes ( const cv::Vec4i & p_houghLine,
const ObjectDetectionInformation & p_objectDetectionInformation )
staticprivate

Determines whether p_houghLine is within any one of the p_objectDetectionInformation object bounding boxes.

Parameters
p_houghLineThe line to check.
p_objectDetectionInformationThe ObjectDetectionInformation struct containing the object bounding boxes.
Returns
true If p_houghLine is within the object bounding boxes found within p_objectDetectionInformation.
false If p_houghLine is NOT within the object bounding boxes found within p_objectDetectionInformation.

Definition at line 256 of file LaneDetector.cpp.

◆ UpdateLineTypes()

void LaneAndObjectDetection::LaneDetector::UpdateLineTypes ( )
private

Determines whether the left, middle, and right lane lines detected are solid, dashed or empty.

Definition at line 279 of file LaneDetector.cpp.

◆ UpdateDrivingState()

void LaneAndObjectDetection::LaneDetector::UpdateDrivingState ( )
private

Determines the current driving state depending upon the absence/presence of left, right and middle lane lines.

Definition at line 306 of file LaneDetector.cpp.

◆ ExecuteDrivingState()

void LaneAndObjectDetection::LaneDetector::ExecuteDrivingState ( )
private

Execute logic based on the current driving state.

Definition at line 368 of file LaneDetector.cpp.

◆ CalculateLanePosition()

void LaneAndObjectDetection::LaneDetector::CalculateLanePosition ( )
private

Determines the lane overlay for the current lane.

Definition at line 400 of file LaneDetector.cpp.

◆ CalculateChangingLanesTurningDirection()

void LaneAndObjectDetection::LaneDetector::CalculateChangingLanesTurningDirection ( )
private

Determines the direction (left, right or neither) that the vehicle is turning while changing lanes.

Definition at line 492 of file LaneDetector.cpp.

Member Data Documentation

◆ m_laneDetectionInformation

LaneDetectionInformation LaneAndObjectDetection::LaneDetector::m_laneDetectionInformation
private

The LaneDetectionInformation struct containing all lane detection-related information.

Definition at line 128 of file LaneDetector.hpp.

◆ m_drivingStateRollingAverage

RollingAverage<Globals::DrivingState> LaneAndObjectDetection::LaneDetector::m_drivingStateRollingAverage
private

The rolling average to determine the driving state.

Definition at line 133 of file LaneDetector.hpp.

◆ m_currentDrivingState

Globals::DrivingState LaneAndObjectDetection::LaneDetector::m_currentDrivingState
private

The current driving state.

Definition at line 138 of file LaneDetector.hpp.

◆ m_leftLaneLines

std::vector<cv::Vec4i> LaneAndObjectDetection::LaneDetector::m_leftLaneLines
private

The left, middle and right lane lines that have been detected for the current frame.

Definition at line 144 of file LaneDetector.hpp.

◆ m_middleLaneLines

std::vector<cv::Vec4i> LaneAndObjectDetection::LaneDetector::m_middleLaneLines
private

The left, middle and right lane lines that have been detected for the current frame.

Definition at line 145 of file LaneDetector.hpp.

◆ m_rightLaneLines

std::vector<cv::Vec4i> LaneAndObjectDetection::LaneDetector::m_rightLaneLines
private

The left, middle and right lane lines that have been detected for the current frame.

Definition at line 146 of file LaneDetector.hpp.

◆ m_changingLanesPreviousDistanceDifference

double LaneAndObjectDetection::LaneDetector::m_changingLanesPreviousDistanceDifference
private

The distance difference that will be compared to in order to determine the direction the vehicle is moving while changing lanes.

Definition at line 153 of file LaneDetector.hpp.

◆ m_leftLineAverageLength

double LaneAndObjectDetection::LaneDetector::m_leftLineAverageLength
private

The average left, middle and right lane line lengths for the current frame.

Definition at line 159 of file LaneDetector.hpp.

◆ m_middleLineAverageLength

double LaneAndObjectDetection::LaneDetector::m_middleLineAverageLength
private

The average left, middle and right lane line lengths for the current frame.

Definition at line 160 of file LaneDetector.hpp.

◆ m_rightLineAverageLength

double LaneAndObjectDetection::LaneDetector::m_rightLineAverageLength
private

The average left, middle and right lane line lengths for the current frame.

Definition at line 161 of file LaneDetector.hpp.

◆ m_changingLanesFrameCount

uint32_t LaneAndObjectDetection::LaneDetector::m_changingLanesFrameCount
private

The number of frames passed since a distance difference was calculated while the vehicle is changing lanes.

Definition at line 167 of file LaneDetector.hpp.

◆ m_changingLanesFirstFrame

bool LaneAndObjectDetection::LaneDetector::m_changingLanesFirstFrame
private

Whether the current frame is the frame in which the driving state changed to CHANGING_LANES.

Definition at line 172 of file LaneDetector.hpp.


The documentation for this class was generated from the following files: