10#include <unordered_map>
12#include <opencv2/core/cvdef.h>
13#include <opencv2/core/types.hpp>
14#include <opencv2/imgproc.hpp>
49 static inline std::string
GetTimeElapsed(
const std::chrono::time_point<std::chrono::high_resolution_clock>& p_startTime)
51 const double MINUTES_IN_HOUR = 60;
52 const double SECONDS_IN_HOUR = 3600;
53 const double SECONDS_IN_MINUTE = 60;
54 const uint32_t PADDING_THRESHOLD = 10;
56 const uint32_t TOTAL_TIME_IN_SECONDS = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - p_startTime).count();
58 const double TOTAL_HOURS = TOTAL_TIME_IN_SECONDS / SECONDS_IN_HOUR;
59 const double TOTAL_MINUTES = (TOTAL_HOURS - std::floor(TOTAL_HOURS)) * MINUTES_IN_HOUR;
60 const double TOTAL_SECONDS = (TOTAL_MINUTES - std::floor(TOTAL_MINUTES)) * SECONDS_IN_MINUTE;
62 const uint32_t HOURS = std::floor(TOTAL_HOURS);
63 const uint32_t MINUTES = std::floor(TOTAL_MINUTES);
64 const uint32_t SECONDS = std::floor(TOTAL_SECONDS);
68 if (HOURS < PADDING_THRESHOLD)
73 output += std::to_string(HOURS);
76 if (MINUTES < PADDING_THRESHOLD)
81 output += std::to_string(MINUTES);
84 if (SECONDS < PADDING_THRESHOLD)
89 output += std::to_string(SECONDS);
97 static inline const std::string
G_CLI_HELP_MESSAGE =
"\nUsage: lane-and-object-detection --input ... --yolo-folder-path ... [optional]\n\nOPTIONS:\n\nGeneric Options:\n\n -h --help Display available options\n\nRequired Options:\n\n -i --input File path or camera ID\n -y --yolo-folder-path Path to the yolo folder\n\nOptional options:\n\n -o --object-detector-type One of: none, standard or tiny (default = none)\n -b --object-detector-backend One of: cpu, gpu or cuda (default = cpu)\n -s --object-detector-blob-size One of: 208, 320, 416, 512 or 608 (default = 208)\n\n";
415 ONLY_LEFT_LANE_MARKING_DETECTED,
416 ONLY_RIGHT_LANE_MARKING_DETECTED,
417 NO_LANE_MARKINGS_DETECTED
424 {DrivingState::WITHIN_LANE,
"Within Lanes" },
425 {DrivingState::CHANGING_LANES,
"WARNING: Changing lanes" },
426 {DrivingState::ONLY_LEFT_LANE_MARKING_DETECTED,
"WARNING: Only left road marking detected" },
427 {DrivingState::ONLY_RIGHT_LANE_MARKING_DETECTED,
"WARNING: Only right road marking detected"},
428 {DrivingState::NO_LANE_MARKINGS_DETECTED,
"WARNING: No road markings detected" },
690 static inline const std::string
G_PERFORMANCE_TESTS_CLI_HELP_MESSAGE =
"Usage: lane-and-object-detection-performance-tests --platform ... --database-path ... --input ... --yolo-folder-path ... --repetitions ...\n\nOPTIONS:\n\nGeneric Options:\n\n-h --help Display available options\n\nRequired Options:\n\n-p --platform The current platform being tested\n-d --database-path Path to SQLite database file\n-i --input Benchmark video file path\n-y --yolo-folder-path Path to the yolo configuration folder\n-r --repetitions Number of repetitions for each test";
700 "YOLO-tiny 288 (CPU)",
701 "YOLO-tiny 288 (GPU)",
704 "YOLO-tiny 320 (CPU)",
705 "YOLO-tiny 320 (GPU)",
708 "YOLO-tiny 416 (CPU)",
709 "YOLO-tiny 416 (GPU)",
712 "YOLO-tiny 512 (CPU)",
713 "YOLO-tiny 512 (GPU)",
716 "YOLO-tiny 608 (CPU)",
717 "YOLO-tiny 608 (GPU)",
723 ObjectDetectorTypes::NONE,
724 ObjectDetectorTypes::TINY,
725 ObjectDetectorTypes::TINY,
726 ObjectDetectorTypes::STANDARD,
727 ObjectDetectorTypes::STANDARD,
728 ObjectDetectorTypes::TINY,
729 ObjectDetectorTypes::TINY,
730 ObjectDetectorTypes::STANDARD,
731 ObjectDetectorTypes::STANDARD,
732 ObjectDetectorTypes::TINY,
733 ObjectDetectorTypes::TINY,
734 ObjectDetectorTypes::STANDARD,
735 ObjectDetectorTypes::STANDARD,
736 ObjectDetectorTypes::TINY,
737 ObjectDetectorTypes::TINY,
738 ObjectDetectorTypes::STANDARD,
739 ObjectDetectorTypes::STANDARD,
740 ObjectDetectorTypes::TINY,
741 ObjectDetectorTypes::TINY,
742 ObjectDetectorTypes::STANDARD,
743 ObjectDetectorTypes::STANDARD,
747 ObjectDetectorBackEnds::NONE,
748 ObjectDetectorBackEnds::CPU,
749 ObjectDetectorBackEnds::GPU,
750 ObjectDetectorBackEnds::CPU,
751 ObjectDetectorBackEnds::GPU,
752 ObjectDetectorBackEnds::CPU,
753 ObjectDetectorBackEnds::GPU,
754 ObjectDetectorBackEnds::CPU,
755 ObjectDetectorBackEnds::GPU,
756 ObjectDetectorBackEnds::CPU,
757 ObjectDetectorBackEnds::GPU,
758 ObjectDetectorBackEnds::CPU,
759 ObjectDetectorBackEnds::GPU,
760 ObjectDetectorBackEnds::CPU,
761 ObjectDetectorBackEnds::GPU,
762 ObjectDetectorBackEnds::CPU,
763 ObjectDetectorBackEnds::GPU,
764 ObjectDetectorBackEnds::CPU,
765 ObjectDetectorBackEnds::GPU,
766 ObjectDetectorBackEnds::CPU,
767 ObjectDetectorBackEnds::GPU,
771 ObjectDetectorBlobSizes::NONE,
772 ObjectDetectorBlobSizes::ONE,
773 ObjectDetectorBlobSizes::ONE,
774 ObjectDetectorBlobSizes::ONE,
775 ObjectDetectorBlobSizes::ONE,
776 ObjectDetectorBlobSizes::TWO,
777 ObjectDetectorBlobSizes::TWO,
778 ObjectDetectorBlobSizes::TWO,
779 ObjectDetectorBlobSizes::TWO,
780 ObjectDetectorBlobSizes::THREE,
781 ObjectDetectorBlobSizes::THREE,
782 ObjectDetectorBlobSizes::THREE,
783 ObjectDetectorBlobSizes::THREE,
784 ObjectDetectorBlobSizes::FOUR,
785 ObjectDetectorBlobSizes::FOUR,
786 ObjectDetectorBlobSizes::FOUR,
787 ObjectDetectorBlobSizes::FOUR,
788 ObjectDetectorBlobSizes::FIVE,
789 ObjectDetectorBlobSizes::FIVE,
790 ObjectDetectorBlobSizes::FIVE,
791 ObjectDetectorBlobSizes::FIVE,
Used for functionality that has not been implemented.
Contains all custom exceptions.
Contains all global and constant objects.
static const uint32_t G_KEY_QUIT
Keyboard values when getting user input.
static const double G_MICROSECONDS_IN_SECOND
Conversion between time units.
static const uint32_t G_SOLID_LINE_LENGTH_THRESHOLD
Threshold length to decide whether a line is to be considered solid line road marking.
static const uint32_t G_UI_RADIUS_RECORDING_DOT
Recording status UI locations.
static const std::unordered_map< DrivingState, std::string > G_DRIVING_STATE_TITLES
The driving state titles to display.
static const uint32_t G_CHANGING_LANES_DISTANCE_DIFFERENCE_FRAME_COUNT_THRESHOLD
The number of frames to wait before calculating another distance difference while the vehicle is chan...
static const cv::Scalar G_COLOUR_LIGHT_BLUE
OpenCV Colours (in BGR format).
static const double G_UI_H1_FONT_SCALE
Font scales for different heading sizes.
static const double G_TOP_MID_POINT_X_LOCATION
Region-of-interest sub-division line equations (y = mx + c).
static const uint32_t G_VIDEO_OUTPUT_FPS
Output video FPS.
static const cv::Range G_ROI_BOUNDING_BOX_Y_RANGE
The bounding box of the region-of-interest which is used to crop debugging frames....
static const int32_t G_OBJECT_DETECTOR_BOUNDING_BOX_HEADER_HEIGHT
Object detection bounding box properties.
static const uint32_t G_ROI_TOP_RIGHT_INDEX
The index values which represent each corner of G_ROI_MASK_POINTS.
static const uint32_t G_FONT_DEFAULT_THICKNESS
Font settings.
static const uint32_t G_ROI_BOUND_BOX_PADDING
The bounding box of the region-of-interest which is used to crop debugging frames....
static const std::string G_UI_TEXT_RECORDING
Text to display whether or not recording.
static const cv::Scalar G_COLOUR_BLACK
OpenCV Colours (in BGR format).
static const uint32_t G_VIDEO_OUTPUT_WIDTH
Output video dimensions.
static const cv::Rect G_UI_RECT_DRIVING_STATE_SUBTITLE
Driving state sub-title UI location (width is the entire screen for centering).
static const cv::Rect G_UI_RECT_RECORDING_ELAPSED_TIME
Recording status UI locations.
static const int32_t G_OBJECT_DETECTOR_OUTPUT_BLOBS_CENTER_Y_COORD_INDEX
The indicies representing various values in the output blobs.
static const uint32_t G_OBJECT_DETECTOR_BOUNDING_BOX_BUFFER
Object detection bounding box properties.
static const double G_RIGHT_LINE_THRESHOLD_M
Region-of-interest sub-division line equations (y = mx + c).
static const uint32_t G_KEY_DEBUG_MODE
Keyboard values when getting user input.
static const uint32_t G_HOUGH_MIN_LINE_LENGTH
Hough transform threshold and properties.
static const std::array< ObjectDetectorBlobSizes, G_PERFORMANCE_TESTS_NUMBER_OF_TESTS > G_PERFORMANCE_TESTS_BLOB_SIZES
Performance tests settings.
static const uint32_t G_VIDEO_INPUT_HEIGHT
Input video dimensions.
static const uint32_t G_VIDEO_INPUT_WIDTH
Input video dimensions.
static const double G_OBJECT_DETECTOR_CONFIDENCE_THRESHOLD
Object detection threshold and properties.
static const std::string G_UI_TEXT_DEBUG_MODE
Text to display whether or not in debug mode.
static const cv::Rect G_UI_RECT_FPS
Performance-related information UI location.
static const double G_OBJECT_DETECTOR_NMS_THRESHOLD
Object detection threshold and properties.
static const double G_RIGHT_LINE_THRESHOLD_C
Region-of-interest sub-division line equations (y = mx + c).
static const int32_t G_ROI_TOP_HEIGHT
Region-of-interest dimensions.
static const int32_t G_ROI_BOTTOM_WIDTH
Region-of-interest dimensions.
static const double G_DIVIDE_BY_TWO
Divide by two.
static const uint32_t G_ROI_BOUNDING_BOX_START_Y
The bounding box of the region-of-interest which is used to crop debugging frames....
static const cv::Scalar G_COLOUR_GREY
OpenCV Colours (in BGR format).
static const cv::Rect G_UI_RECT_DRIVING_STATE
Driving state UI location (width is the entire screen for centering).
static const std::string G_PERFORMANCE_TESTS_CLI_HELP_MESSAGE
CLI help message for the performance tests.
static const int32_t G_OBJECT_DETECTOR_OUTPUT_BLOBS_HEIGHT_INDEX
The indicies representing various values in the output blobs.
static const uint32_t G_ROI_BOUNDING_BOX_START_X
The bounding box of the region-of-interest which is used to crop debugging frames....
static const uint32_t G_VEC4_X1_INDEX
Hough line index mapping.
static const cv::Range G_ROI_BOUNDING_BOX_X_RANGE
The bounding box of the region-of-interest which is used to crop debugging frames....
static const uint32_t G_VIDEO_OUTPUT_HEIGHT
Output video dimensions.
static const int32_t G_HOUGH_LINE_THICKNESS
The thickness of the hough lines drawn in debug mode.
static const cv::Scalar G_COLOUR_GREEN
OpenCV Colours (in BGR format).
static const uint32_t G_VEC4_X2_INDEX
Hough line index mapping.
static const cv::Scalar G_COLOUR_WHITE
OpenCV Colours (in BGR format).
static const uint32_t G_VEC4_Y1_INDEX
Hough line index mapping.
static const double G_DEBUGGING_FRAME_SCALING_FACTOR
Scaling factor for debugging frames.
static const std::array< std::string, G_OBJECT_DETECTOR_NUMBER_OF_DETECTABLE_OBJECTS > G_OBJECT_DETECTOR_OBJECT_NAMES
Names of detectable objects. The order is significant and should not be changed.
static const int32_t G_ROI_BOTTOM_HEIGHT
Region-of-interest dimensions.
static const uint32_t G_ROI_BOTTOM_RIGHT_INDEX
The index values which represent each corner of G_ROI_MASK_POINTS.
static const uint32_t G_OBJECT_DETECTOR_NUMBER_OF_DETECTABLE_OBJECTS
Names of detectable objects. The order is significant and should not be changed.
static const double G_BOTTOM_TWO_THIRD_LOCATION
Region-of-interest sub-division line equations (y = mx + c).
static const uint32_t G_HOUGH_MAX_LINE_GAP
Hough transform threshold and properties.
static const double G_UI_H2_FONT_SCALE
Font scales for different heading sizes.
static const std::string G_YOLO_NAME
The name of the YOLO version being used.
static const double G_OBJECT_DETECTOR_BOUNDING_BOX_FONT_SCALE
Object detection bounding box properties.
static const int32_t G_FONT_DEFAULT_VERTICAL_PADDING
Font settings.
static const int32_t G_FONT_DEFAULT_HORIZONTAL_PADDING
Font settings.
ObjectDetectorTypes
The type of object detector to use with an option to disable object detection. The tiny version is mo...
static const double G_FONT_DEFAULT_DECREMENT
Font settings.
static const uint32_t G_DEFAULT_ROLLING_AVERAGE_SIZE
Default rolling average size.
static const double G_RIGHT_EDGE_OF_MASK_M
Region-of-interest sub-division line equations (y = mx + c).
static const int32_t G_OBJECT_DETECTOR_OUTPUT_BLOBS_OBJECT_SCORES_START_INDEX
The indicies representing various values in the output blobs.
static const std::string G_TIME_UNIT
Time unit for performance-related frame times.
static const double G_LEFT_LINE_THRESHOLD_M
Region-of-interest sub-division line equations (y = mx + c).
static const double G_LEFT_EDGE_OF_MASK_M
Region-of-interest sub-division line equations (y = mx + c).
static const std::array< ObjectDetectorBackEnds, G_PERFORMANCE_TESTS_NUMBER_OF_TESTS > G_PERFORMANCE_TESTS_BACK_END_TYPES
Performance tests settings.
static const cv::Point G_UI_POINT_RECORDING_DOT
Recording status UI locations.
ObjectDetectorBackEnds
The supported backends for the object detector to run on. In theory, GPU should be significantly more...
static const double G_FONT_DEFAULT_SCALE
Font settings.
static const cv::Scalar G_COLOUR_YELLOW
OpenCV Colours (in BGR format).
static const cv::Scalar G_COLOUR_PURPLE
OpenCV Colours (in BGR format).
static const uint32_t G_ROI_TOP_LEFT_INDEX
The index values which represent each corner of G_ROI_MASK_POINTS.
static const cv::Rect G_UI_RECT_NOT_RECORDING_STATUS
Recording status UI locations.
static const cv::Scalar G_COLOUR_RED
OpenCV Colours (in BGR format).
static const int32_t G_OBJECT_DETECTOR_OUTPUT_BLOBS_CENTER_X_COORD_INDEX
The indicies representing various values in the output blobs.
static const double G_LEFT_EDGE_OF_MASK_C
Region-of-interest sub-division line equations (y = mx + c).
static const uint32_t G_VEC4_Y2_INDEX
Hough line index mapping.
static const std::array< cv::Point, G_NUMBER_OF_POINTS > G_ROI_MASK_POINTS
Region-of-interest points. Below is how the indicies of the array map to the points.
static const std::map< std::string, cv::Scalar > G_OBJECT_DETECTOR_OBJECT_NAMES_AND_COLOURS
Object names and bounding box colours. G_OPENCV_WHITE is used as the default colour while custom colo...
static const double G_HOUGH_RHO
Hough transform threshold and properties.
static const uint32_t G_HOUGH_THRESHOLD
Hough transform threshold and properties.
static const double G_HOUGH_LINE_HORIZONTAL_GRADIENT_THRESHOLD
Threshold gradient to decide whether a line is to be considered horizontal.
static std::string GetTimeElapsed(const std::chrono::time_point< std::chrono::high_resolution_clock > &p_startTime)
Gets the elapsed time from p_startTime to now.
static const uint32_t G_FONT_DEFAULT_FACE
Font settings.
static const uint32_t G_NUMBER_OF_POINTS
Region-of-interest points. Below is how the indicies of the array map to the points.
static const uint32_t G_ROI_BOUNDING_BOX_END_X
The bounding box of the region-of-interest which is used to crop debugging frames....
static const int32_t G_UI_BOTTOM_BAR_HEIGHT
UI heights.
static const uint32_t G_KEY_TOGGLE_SAVE_OUTPUT
Keyboard values when getting user input.
static const double G_RIGHT_EDGE_OF_MASK_C
Region-of-interest sub-division line equations (y = mx + c).
static const double G_OBJECT_DETECTOR_SCALE_FACTOR
Object detection threshold and properties.
static const int32_t G_OBJECT_DETECTOR_BOUNDING_BOX_TEXT_HEIGHT_OFFSET
Object detection bounding box properties.
DrivingState
The different driving states supported by the lane detector.
static const double G_HOUGH_THETA
Hough transform threshold and properties.
static const uint32_t G_PERFORMANCE_TESTS_NUMBER_OF_TESTS
Performance tests settings.
static const std::string G_CLI_HELP_MESSAGE
CLI help message for the video manager.
static const std::array< std::string, G_PERFORMANCE_TESTS_NUMBER_OF_TESTS > G_PERFORMANCE_TESTS_NAMES
Performance tests settings.
static const uint32_t G_CANNY_ALGORITHM_UPPER_THRESHOLD
Canny algorithm thresholds.
static const std::array< ObjectDetectorTypes, G_PERFORMANCE_TESTS_NUMBER_OF_TESTS > G_PERFORMANCE_TESTS_OBJECT_DETECTOR_TYPES
Performance tests settings.
static const int32_t G_UI_SUBTITLE_HEIGHT
UI heights.
static const cv::Scalar G_COLOUR_BLUE
OpenCV Colours (in BGR format).
static const int32_t G_UI_TITLE_HEIGHT
UI heights.
static const uint32_t G_CANNY_ALGORITHM_LOWER_THRESHOLD
Canny algorithm thresholds.
static const int32_t G_ROI_TOP_WIDTH
Region-of-interest dimensions.
static const int32_t G_OBJECT_DETECTOR_OUTPUT_BLOBS_WIDTH_INDEX
The indicies representing various values in the output blobs.
static const double G_BOTTOM_ONE_THIRD_LOCATION
Region-of-interest sub-division line equations (y = mx + c).
static const cv::Scalar G_COLOUR_LIGHT_RED
OpenCV Colours (in BGR format).
static const cv::Scalar G_LANE_OVERLAY_COLOUR
Translucent colour of the overlay for the current lane.
static const uint32_t G_ROI_BOUNDING_BOX_END_Y
The bounding box of the region-of-interest which is used to crop debugging frames....
static const std::string G_UI_TEXT_NOT_RECORDING
Text to display whether or not recording.
static const cv::Rect G_UI_RECT_RECORDING_STATUS
Recording status UI locations.
static const std::string G_UI_TEXT_NOT_DEBUG_MODE
Text to display whether or not in debug mode.
ObjectDetectorBlobSizes
The supported blob sizes for the object detector to run with. The larger the blob size the more perfo...
static const uint32_t G_ROI_BOTTOM_LEFT_INDEX
The index values which represent each corner of G_ROI_MASK_POINTS.
static const cv::Rect G_UI_RECT_TIMESTAMP
Timestamp UI location.
static const cv::Scalar G_COLOUR_ORANGE
OpenCV Colours (in BGR format).
static const int32_t G_OBJECT_DETECTOR_BOUNDING_BOX_BORDER_THICKNESS
Object detection bounding box properties.
static const uint32_t G_CONVERT_DECIMAL_TO_PERCENTAGE
Convert a decimal value to a percentage.
static const double G_LEFT_LINE_THRESHOLD_C
Region-of-interest sub-division line equations (y = mx + c).
static const int32_t G_OBJECT_DETECTOR_BOUNDING_BOX_CHARACTER_WIDTH
Object detection bounding box properties.
static const cv::Rect G_UI_RECT_DEBUG_MODE_STATUS
Debug mode status UI location.