9#include <opencv2/core/types.hpp>
10#include <opencv2/highgui.hpp>
11#include <opencv2/videoio.hpp>
13#include "detectors/LaneDetector.hpp"
14#include "detectors/ObjectDetector.hpp"
15#include "helpers/FrameBuilder.hpp"
16#include "helpers/Globals.hpp"
17#include "helpers/Information.hpp"
18#include "helpers/Performance.hpp"
20#include "helpers/VideoManager.hpp"
33 const std::string& p_yoloFolderPath,
43 SetProperties(p_inputVideoCamera, p_yoloFolderPath, p_objectDetectorTypes, p_objectDetectorBackEnds, p_objectDetectorBlobSizes);
47 const std::string& p_yoloFolderPath,
57 SetProperties(p_inputVideoFilePath, p_yoloFolderPath, p_objectDetectorTypes, p_objectDetectorBackEnds, p_objectDetectorBlobSizes);
67 std::string parsedInputVideoFilePath;
68 std::string parsedYoloFolderPath;
75 for (
const std::string& argument : p_commandLineArguments)
77 if (argument ==
"-h" || argument ==
"--help")
85 if (argument ==
"-i" || argument ==
"--input")
87 parsedInputVideoFilePath = p_commandLineArguments.at(index + 1);
90 if (argument ==
"-y" || argument ==
"--yolo-folder-path")
92 parsedYoloFolderPath = p_commandLineArguments.at(index + 1);
95 if (argument ==
"-o" || argument ==
"--object-detector-type")
97 if (p_commandLineArguments.at(index + 1) ==
"none")
99 parsedObjectDetectorTypes = Globals::ObjectDetectorTypes::NONE;
102 else if (p_commandLineArguments.at(index + 1) ==
"standard")
104 parsedObjectDetectorTypes = Globals::ObjectDetectorTypes::STANDARD;
107 else if (p_commandLineArguments.at(index + 1) ==
"tiny")
109 parsedObjectDetectorTypes = Globals::ObjectDetectorTypes::TINY;
119 if (argument ==
"-b" || argument ==
"--object-detector-backend")
121 if (p_commandLineArguments.at(index + 1) ==
"cpu")
123 parsedObjectDetectorBackEnds = Globals::ObjectDetectorBackEnds::CPU;
126 else if (p_commandLineArguments.at(index + 1) ==
"gpu")
128 parsedObjectDetectorBackEnds = Globals::ObjectDetectorBackEnds::GPU;
131 else if (p_commandLineArguments.at(index + 1) ==
"cuda")
133 parsedObjectDetectorBackEnds = Globals::ObjectDetectorBackEnds::CUDA;
143 if (argument ==
"-s" || argument ==
"--object-detector-blob-size")
159 if (parsedInputVideoFilePath.empty() ||
160 parsedYoloFolderPath.empty() ||
161 (parsedObjectDetectorTypes != Globals::ObjectDetectorTypes::NONE && (parsedObjectDetectorBackEnds == Globals::ObjectDetectorBackEnds::NONE || parsedObjectDetectorBlobSizes == Globals::ObjectDetectorBlobSizes::NONE)))
167 SetProperties(parsedInputVideoFilePath, parsedYoloFolderPath, parsedObjectDetectorTypes, parsedObjectDetectorBackEnds, parsedObjectDetectorBlobSizes);
176 const std::string& p_yoloFolderPath,
185 std::cout <<
"\nERROR: Input video camera '" + std::to_string(p_inputVideoCamera) +
"' cannot be found!\n";
197 m_objectDetector.SetProperties(p_yoloFolderPath, p_objectDetectorTypes, p_objectDetectorBackEnds, p_objectDetectorBlobSizes);
203 const std::string& p_yoloFolderPath,
212 std::cout <<
"\nERROR: Input video file path '" + p_inputVideoFilePath +
"' cannot be found!\n";
224 m_objectDetector.SetProperties(p_yoloFolderPath, p_objectDetectorTypes, p_objectDetectorBackEnds, p_objectDetectorBlobSizes);
256 cv::imshow(
"roiFrame",
m_laneDetector.GetInformation().m_roiFrame);
257 cv::imshow(
"cannyFrame",
m_laneDetector.GetInformation().m_cannyFrame);
258 cv::imshow(
"houghLinesFrame",
m_laneDetector.GetInformation().m_houghLinesFrame);
261 switch (cv::waitKey(1))
295 cv::destroyWindow(
"roiFrame");
296 cv::destroyWindow(
"cannyFrame");
297 cv::destroyWindow(
"houghLinesFrame");
309 const std::string OUTPUT_FILE_NAME = std::format(
"{:%Y-%m-%d-%H-%M-%S}-output.mp4", std::chrono::system_clock::now());
312 cv::VideoWriter::fourcc(
'm',
'p',
'4',
'v'),
318 std::cout << std::format(
"\nERROR: Output video file '{}' could not be opened! Recording stopped!\n", OUTPUT_FILE_NAME);
339 cv::destroyAllWindows();
static void UpdateFrame(cv::Mat &p_frame, const ObjectDetectionInformation &p_objectDetectionInformation, const LaneDetectionInformation &p_laneDetectionInformation, const PerformanceInformation &p_performanceInformation, const VideoManagerInformation &p_videoManagerInformation)
Updates p_frame with object detection, lane detection, performance and video manager information.
~VideoManager()
Destructs a VideoManager object.
ObjectDetector m_objectDetector
The object detector.
void SetProperties(const int32_t &p_inputVideoCamera, const std::string &p_yoloFolderPath, const Globals::ObjectDetectorTypes &p_objectDetectorTypes, const Globals::ObjectDetectorBackEnds &p_objectDetectorBackEnds, const Globals::ObjectDetectorBlobSizes &p_objectDetectorBlobSizes)
Set the properties of the VideoManager object.
VideoManagerInformation m_videoManagerInformation
The VideoManagerInformation struct containing all video manager-related information.
cv::VideoCapture m_inputVideo
Represents the input video stream.
VideoManager()
Constructs a new VideoManager object.
cv::VideoWriter m_outputVideo
Represents the output video stream.
LaneDetector m_laneDetector
The lane detector.
std::chrono::time_point< std::chrono::high_resolution_clock > m_saveOutputStartTime
The time that the output started to be saved locally.
void ToggleDebugMode()
Toggles the debug mode and whether to destroy the debug frames.
void ToggleSaveOutput()
Toggles whether the output video stream is saved locally. If toggled on, it creates a new file in the...
void RunLaneAndObjectDetector()
Orchestration function which contains the main program loop.
Performance m_performance
The frame time and current/average frames per second performance calculator.
Performance GetPerformance()
Get the performance object to extract performance-related information.
void Quit()
Destroys all windows and releases all input/output videos.
cv::Mat m_currentFrame
Represents the current frame being processed.
static const uint32_t G_KEY_QUIT
Keyboard values when getting user input.
static const uint32_t G_VIDEO_OUTPUT_FPS
Output video FPS.
static const std::string G_UI_TEXT_RECORDING
Text to display whether or not recording.
static const uint32_t G_VIDEO_OUTPUT_WIDTH
Output video dimensions.
static const uint32_t G_KEY_DEBUG_MODE
Keyboard values when getting user input.
static const uint32_t G_VIDEO_INPUT_HEIGHT
Input video dimensions.
static const uint32_t G_VIDEO_INPUT_WIDTH
Input video dimensions.
static const std::string G_UI_TEXT_DEBUG_MODE
Text to display whether or not in debug mode.
static const uint32_t G_VIDEO_OUTPUT_HEIGHT
Output video dimensions.
ObjectDetectorTypes
The type of object detector to use with an option to disable object detection. The tiny version is mo...
ObjectDetectorBackEnds
The supported backends for the object detector to run on. In theory, GPU should be significantly more...
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_KEY_TOGGLE_SAVE_OUTPUT
Keyboard values when getting user input.
static const std::string G_CLI_HELP_MESSAGE
CLI help message for the video manager.
static const std::string G_UI_TEXT_NOT_RECORDING
Text to display whether or not recording.
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...
Contains all Lane-and-Object-Detection objects.