Lane and Object Detection
Using OpenCV and YOLOv7
|
Orchestration class which reads the input, runs the lane and object detectors, displays the detected output and saves output video stream locally. More...
#include "VideoManager.hpp"
Public Member Functions | |
VideoManager () | |
Constructs a new VideoManager object. | |
VideoManager (const int32_t &p_inputVideoCamera, const std::string &p_yoloFolderPath, const Globals::ObjectDetectorTypes &p_objectDetectorTypes, const Globals::ObjectDetectorBackEnds &p_objectDetectorBackEnds=Globals::ObjectDetectorBackEnds::CPU, const Globals::ObjectDetectorBlobSizes &p_objectDetectorBlobSizes=Globals::ObjectDetectorBlobSizes::ONE) | |
Constructs a new VideoManager object for use with an OpenCV camera input (for API use). | |
VideoManager (const std::string &p_inputVideoFilePath, const std::string &p_yoloFolderPath, const Globals::ObjectDetectorTypes &p_objectDetectorTypes, const Globals::ObjectDetectorBackEnds &p_objectDetectorBackEnds=Globals::ObjectDetectorBackEnds::CPU, const Globals::ObjectDetectorBlobSizes &p_objectDetectorBlobSizes=Globals::ObjectDetectorBlobSizes::ONE) | |
Constructs a new VideoManager object for use with a video file input (for API use). | |
VideoManager (const std::vector< std::string > &p_commandLineArguments) | |
Constructs a new VideoManager object (for CLI use). | |
~VideoManager () | |
Destructs a VideoManager object. | |
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. | |
void | SetProperties (const std::string &p_inputVideoFilePath, 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. | |
void | RunLaneAndObjectDetector () |
Orchestration function which contains the main program loop. | |
Performance | GetPerformance () |
Get the performance object to extract performance-related information. | |
VideoManager (const VideoManager &p_videoManager)=delete | |
Disable constructing a new VideoManager object using copy constructor. | |
VideoManager (const VideoManager &&p_videoManager)=delete | |
Disable constructing a new VideoManager object using move constructor. | |
VideoManager & | operator= (const VideoManager &p_videoManager)=delete |
Disable constructing a new VideoManager object using copy assignment operator. | |
VideoManager & | operator= (const VideoManager &&p_videoManager)=delete |
Disable constructing a new VideoManager object using move assignment operator. |
Private Member Functions | |
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 format YYYY-MM-DD-HH:mm:ss-output.mp4, and if toggled off, it closes the output file. | |
void | Quit () |
Destroys all windows and releases all input/output videos. |
Private Attributes | |
cv::VideoCapture | m_inputVideo |
Represents the input video stream. | |
cv::VideoWriter | m_outputVideo |
Represents the output video stream. | |
cv::Mat | m_currentFrame |
Represents the current frame being processed. | |
LaneDetector | m_laneDetector |
The lane detector. | |
ObjectDetector | m_objectDetector |
The object detector. | |
Performance | m_performance |
The frame time and current/average frames per second performance calculator. | |
VideoManagerInformation | m_videoManagerInformation |
The VideoManagerInformation struct containing all video manager-related information. | |
std::chrono::time_point< std::chrono::high_resolution_clock > | m_saveOutputStartTime |
The time that the output started to be saved locally. |
Orchestration class which reads the input, runs the lane and object detectors, displays the detected output and saves output video stream locally.
Definition at line 28 of file VideoManager.hpp.
|
explicit |
Constructs a new VideoManager object.
Definition at line 24 of file VideoManager.cpp.
|
explicit |
Constructs a new VideoManager object for use with an OpenCV camera input (for API use).
p_inputVideoCamera | Camera Id of the video capturing device to open using the OpenCV VideoCapture class. |
p_yoloFolderPath | The folder containing the .cfg and .weights YOLO files. |
p_objectDetectorTypes | The type of object detector to use with an option to disable object detection. The tiny version is more performant at the cost of accuracy. |
p_objectDetectorBackEnds | The supported backends for the object detector to run on. In theory, GPU should be significantly more performant. For maximum performance CUDA should be used as the backend, however, this requires building OpenCV with CUDA which is not supported with this projects built-in installation script. |
p_objectDetectorBlobSizes | The supported blob sizes for the object detector to run with. The larger the blob size the more performant the detector at the cost of performance. |
Definition at line 32 of file VideoManager.cpp.
|
explicit |
Constructs a new VideoManager object for use with a video file input (for API use).
p_inputVideoFilePath | The file path of the video file to open using the OpenCV VideoCapture class. |
p_yoloFolderPath | The folder containing the .cfg and .weights YOLO files. |
p_objectDetectorTypes | The type of object detector to use with an option to disable object detection. The tiny version is more performant at the cost of accuracy. |
p_objectDetectorBackEnds | The supported backends for the object detector to run on. In theory, GPU should be significantly more performant. For maximum performance CUDA should be used as the backend, however, this requires building OpenCV with CUDA which is not supported with this projects built-in installation script. |
p_objectDetectorBlobSizes | The supported blob sizes for the object detector to run with. The larger the blob size the more performant the detector at the cost of performance. |
Definition at line 46 of file VideoManager.cpp.
|
explicit |
Constructs a new VideoManager object (for CLI use).
Usage: lane-and-object-detection –input ... –yolo-folder-path ... –object-detector-type ... [optional]
OPTIONS:
Generic Options:
-h –help Display available options.
Required Options:
-i –input File path or camera ID -y –yolo-folder-path Path to the yolo folder
Optional options:
-o –object-detector-type One of: none, standard or tiny. (default = none) -b –object-detector-backend One of: cpu or cuda (default = cpu) -s –object-detector-blob-size One of: 208, 320, 416, 512 or 608 (default = 208)
p_commandLineArguments | List of all command line arguments. |
Definition at line 60 of file VideoManager.cpp.
LaneAndObjectDetection::VideoManager::~VideoManager | ( | ) |
Destructs a VideoManager object.
Definition at line 170 of file VideoManager.cpp.
|
delete |
Disable constructing a new VideoManager object using copy constructor.
p_videoManager | The VideoManager to copy. |
|
delete |
Disable constructing a new VideoManager object using move constructor.
p_videoManager | The VideoManager to copy. |
void LaneAndObjectDetection::VideoManager::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.
p_inputVideoCamera | Camera ID of the video capturing device to open using the OpenCV VideoCapture class. |
p_yoloFolderPath | The folder containing the .cfg and .weights YOLO files. |
p_objectDetectorTypes | The type of object detector to use with an option to disable object detection. The tiny version is more performant at the cost of accuracy. |
p_objectDetectorBackEnds | The supported backends for the object detector to run on. In theory, GPU should be significantly more performant. For maximum performance CUDA should be used as the backend, however, this requires building OpenCV with CUDA which is not supported with this projects built-in installation script. |
p_objectDetectorBlobSizes | The supported blob sizes for the object detector to run with. The larger the blob size the more performant the detector at the cost of performance. |
Definition at line 175 of file VideoManager.cpp.
void LaneAndObjectDetection::VideoManager::SetProperties | ( | const std::string & | p_inputVideoFilePath, |
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.
p_inputVideoFilePath | The file path of the video file to open using the OpenCV VideoCapture class. |
p_yoloFolderPath | The folder containing the .cfg and .weights YOLO files. |
p_objectDetectorTypes | The type of object detector to use with an option to disable object detection. The tiny version is more performant at the cost of accuracy. |
p_objectDetectorBackEnds | The supported backends for the object detector to run on. In theory, GPU should be significantly more performant. For maximum performance CUDA should be used as the backend, however, this requires building OpenCV with CUDA which is not supported with this projects built-in installation script. |
p_objectDetectorBlobSizes | The supported blob sizes for the object detector to run with. The larger the blob size the more performant the detector at the cost of performance. |
Definition at line 202 of file VideoManager.cpp.
void LaneAndObjectDetection::VideoManager::RunLaneAndObjectDetector | ( | ) |
Orchestration function which contains the main program loop.
Definition at line 229 of file VideoManager.cpp.
Performance LaneAndObjectDetection::VideoManager::GetPerformance | ( | ) |
Get the performance object to extract performance-related information.
Definition at line 283 of file VideoManager.cpp.
|
delete |
Disable constructing a new VideoManager object using copy assignment operator.
p_videoManager | The VideoManager to copy. |
|
delete |
Disable constructing a new VideoManager object using move assignment operator.
p_videoManager | The VideoManager to copy. |
|
private |
Toggles the debug mode and whether to destroy the debug frames.
Definition at line 288 of file VideoManager.cpp.
|
private |
Toggles whether the output video stream is saved locally. If toggled on, it creates a new file in the format YYYY-MM-DD-HH:mm:ss-output.mp4, and if toggled off, it closes the output file.
Definition at line 301 of file VideoManager.cpp.
|
private |
Destroys all windows and releases all input/output videos.
Definition at line 335 of file VideoManager.cpp.
|
private |
Represents the input video stream.
Definition at line 204 of file VideoManager.hpp.
|
private |
Represents the output video stream.
Definition at line 209 of file VideoManager.hpp.
|
private |
Represents the current frame being processed.
Definition at line 214 of file VideoManager.hpp.
|
private |
The lane detector.
Definition at line 219 of file VideoManager.hpp.
|
private |
The object detector.
Definition at line 224 of file VideoManager.hpp.
|
private |
The frame time and current/average frames per second performance calculator.
Definition at line 229 of file VideoManager.hpp.
|
private |
The VideoManagerInformation struct containing all video manager-related information.
Definition at line 234 of file VideoManager.hpp.
|
private |
The time that the output started to be saved locally.
Definition at line 239 of file VideoManager.hpp.