Lane and Object Detection
Using OpenCV and YOLOv7
Loading...
Searching...
No Matches
LaneDetector.hpp
1#pragma once
2
3#include <cstdint>
4#include <deque>
5#include <vector>
6
7#include <opencv2/core/mat.hpp>
8#include <opencv2/core/matx.hpp>
9
10#include "helpers/Globals.hpp"
11#include "helpers/Information.hpp"
12
18{
24 {
25 public:
29 explicit LaneDetector();
30
39 void RunLaneDetector(const cv::Mat& p_frame, const ObjectDetectionInformation& p_objectDetectionInformation, const bool& p_debugMode);
40
47
48 private:
57 void AnalyseHoughLines(const std::vector<cv::Vec4i>& p_houghLines, const ObjectDetectionInformation& p_objectDetectionInformation, const bool& p_debugMode);
58
67 static bool IsLineWithinObjectBoundingBoxes(const cv::Vec4i& p_houghLine, const ObjectDetectionInformation& p_objectDetectionInformation);
68
72 void UpdateLineTypes();
73
77 void UpdateDrivingState();
78
83
88
93
100 template<typename T>
102 {
103 public:
107 explicit RollingAverage();
108
116 T CalculateRollingAverage(const T& p_nextInput);
117
118 private:
123 };
124
129
134
139
144 std::vector<cv::Vec4i> m_leftLaneLines;
145 std::vector<cv::Vec4i> m_middleLaneLines;
146 std::vector<cv::Vec4i> m_rightLaneLines;
148
154
163
168
173 };
174}
Calculates a rolling average to provide a smoothed view of state trends over time....
RollingAverage()
Constructs a new RollingAverage object.
std::deque< T > m_rollingAverageArray
A double-ended queue representing the states stored in the rolling average.
T CalculateRollingAverage(const T &p_nextInput)
Adds p_nextInput to the rolling average buffer and returns the most frequent value within the rolling...
LaneDetectionInformation GetInformation()
Get the LaneDetectionInformation struct.
void CalculateChangingLanesTurningDirection()
Determines the direction (left, right or neither) that the vehicle is turning while changing lanes.
Globals::DrivingState m_currentDrivingState
The current driving state.
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 ...
std::vector< cv::Vec4i > m_middleLaneLines
The left, middle and right lane lines that have been detected for the current frame.
double m_middleLineAverageLength
The average left, middle and right lane line lengths for the current frame.
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...
void ExecuteDrivingState()
Execute logic based on the current driving state.
uint32_t m_changingLanesFrameCount
The number of frames passed since a distance difference was calculated while the vehicle is changing ...
LaneDetector()
Construct a new LaneDetector object.
bool m_changingLanesFirstFrame
Whether the current frame is the frame in which the driving state changed to CHANGING_LANES.
RollingAverage< Globals::DrivingState > m_drivingStateRollingAverage
The rolling average to determine the driving state.
std::vector< cv::Vec4i > m_rightLaneLines
The left, middle and right lane lines that have been detected for the current frame.
double m_rightLineAverageLength
The average left, middle and right lane line lengths for the current frame.
LaneDetectionInformation m_laneDetectionInformation
The LaneDetectionInformation struct containing all lane detection-related information.
void UpdateDrivingState()
Determines the current driving state depending upon the absence/presence of left, right and middle la...
double m_changingLanesPreviousDistanceDifference
The distance difference that will be compared to in order to determine the direction the vehicle is m...
void UpdateLineTypes()
Determines whether the left, middle, and right lane lines detected are solid, dashed or empty.
void RunLaneDetector(const cv::Mat &p_frame, const ObjectDetectionInformation &p_objectDetectionInformation, const bool &p_debugMode)
Runs the lane detector against p_frame.
double m_leftLineAverageLength
The average left, middle and right lane line lengths for the current frame.
std::vector< cv::Vec4i > m_leftLaneLines
The left, middle and right lane lines that have been detected for the current frame.
void CalculateLanePosition()
Determines the lane overlay for the current lane.
DrivingState
The different driving states supported by the lane detector.
Definition Globals.hpp:412
Contains all Lane-and-Object-Detection objects.
The information needed by FrameBuilder to update frame with lane detection information.
The information needed by FrameBuilder to update frame with object detection information.