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

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.
VideoManageroperator= (const VideoManager &p_videoManager)=delete
 Disable constructing a new VideoManager object using copy assignment operator.
VideoManageroperator= (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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ VideoManager() [1/6]

LaneAndObjectDetection::VideoManager::VideoManager ( )
explicit

Constructs a new VideoManager object.

Warning
SetProperties() should be used to initialise the necessary member variables before calling Run().

Definition at line 24 of file VideoManager.cpp.

◆ VideoManager() [2/6]

LaneAndObjectDetection::VideoManager::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 )
explicit

Constructs a new VideoManager object for use with an OpenCV camera input (for API use).

Parameters
p_inputVideoCameraCamera Id of the video capturing device to open using the OpenCV VideoCapture class.
p_yoloFolderPathThe folder containing the .cfg and .weights YOLO files.
p_objectDetectorTypesThe 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_objectDetectorBackEndsThe 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_objectDetectorBlobSizesThe 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.

◆ VideoManager() [3/6]

LaneAndObjectDetection::VideoManager::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 )
explicit

Constructs a new VideoManager object for use with a video file input (for API use).

Parameters
p_inputVideoFilePathThe file path of the video file to open using the OpenCV VideoCapture class.
p_yoloFolderPathThe folder containing the .cfg and .weights YOLO files.
p_objectDetectorTypesThe 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_objectDetectorBackEndsThe 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_objectDetectorBlobSizesThe 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.

◆ VideoManager() [4/6]

LaneAndObjectDetection::VideoManager::VideoManager ( const std::vector< std::string > & p_commandLineArguments)
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)

Parameters
p_commandLineArgumentsList of all command line arguments.

Definition at line 60 of file VideoManager.cpp.

◆ ~VideoManager()

LaneAndObjectDetection::VideoManager::~VideoManager ( )

Destructs a VideoManager object.

Definition at line 170 of file VideoManager.cpp.

◆ VideoManager() [5/6]

LaneAndObjectDetection::VideoManager::VideoManager ( const VideoManager & p_videoManager)
delete

Disable constructing a new VideoManager object using copy constructor.

Parameters
p_videoManagerThe VideoManager to copy.

◆ VideoManager() [6/6]

LaneAndObjectDetection::VideoManager::VideoManager ( const VideoManager && p_videoManager)
delete

Disable constructing a new VideoManager object using move constructor.

Parameters
p_videoManagerThe VideoManager to copy.

Member Function Documentation

◆ SetProperties() [1/2]

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.

Parameters
p_inputVideoCameraCamera ID of the video capturing device to open using the OpenCV VideoCapture class.
p_yoloFolderPathThe folder containing the .cfg and .weights YOLO files.
p_objectDetectorTypesThe 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_objectDetectorBackEndsThe 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_objectDetectorBlobSizesThe 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.

◆ SetProperties() [2/2]

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.

Parameters
p_inputVideoFilePathThe file path of the video file to open using the OpenCV VideoCapture class.
p_yoloFolderPathThe folder containing the .cfg and .weights YOLO files.
p_objectDetectorTypesThe 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_objectDetectorBackEndsThe 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_objectDetectorBlobSizesThe 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.

◆ RunLaneAndObjectDetector()

void LaneAndObjectDetection::VideoManager::RunLaneAndObjectDetector ( )

Orchestration function which contains the main program loop.

Definition at line 229 of file VideoManager.cpp.

◆ GetPerformance()

Performance LaneAndObjectDetection::VideoManager::GetPerformance ( )

Get the performance object to extract performance-related information.

Returns
Performance The performance object containing performance-related information.

Definition at line 283 of file VideoManager.cpp.

◆ operator=() [1/2]

VideoManager & LaneAndObjectDetection::VideoManager::operator= ( const VideoManager & p_videoManager)
delete

Disable constructing a new VideoManager object using copy assignment operator.

Parameters
p_videoManagerThe VideoManager to copy.

◆ operator=() [2/2]

VideoManager & LaneAndObjectDetection::VideoManager::operator= ( const VideoManager && p_videoManager)
delete

Disable constructing a new VideoManager object using move assignment operator.

Parameters
p_videoManagerThe VideoManager to copy.

◆ ToggleDebugMode()

void LaneAndObjectDetection::VideoManager::ToggleDebugMode ( )
private

Toggles the debug mode and whether to destroy the debug frames.

Definition at line 288 of file VideoManager.cpp.

◆ ToggleSaveOutput()

void LaneAndObjectDetection::VideoManager::ToggleSaveOutput ( )
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.

◆ Quit()

void LaneAndObjectDetection::VideoManager::Quit ( )
private

Destroys all windows and releases all input/output videos.

Definition at line 335 of file VideoManager.cpp.

Member Data Documentation

◆ m_inputVideo

cv::VideoCapture LaneAndObjectDetection::VideoManager::m_inputVideo
private

Represents the input video stream.

Definition at line 204 of file VideoManager.hpp.

◆ m_outputVideo

cv::VideoWriter LaneAndObjectDetection::VideoManager::m_outputVideo
private

Represents the output video stream.

Definition at line 209 of file VideoManager.hpp.

◆ m_currentFrame

cv::Mat LaneAndObjectDetection::VideoManager::m_currentFrame
private

Represents the current frame being processed.

Definition at line 214 of file VideoManager.hpp.

◆ m_laneDetector

LaneDetector LaneAndObjectDetection::VideoManager::m_laneDetector
private

The lane detector.

Definition at line 219 of file VideoManager.hpp.

◆ m_objectDetector

ObjectDetector LaneAndObjectDetection::VideoManager::m_objectDetector
private

The object detector.

Definition at line 224 of file VideoManager.hpp.

◆ m_performance

Performance LaneAndObjectDetection::VideoManager::m_performance
private

The frame time and current/average frames per second performance calculator.

Definition at line 229 of file VideoManager.hpp.

◆ m_videoManagerInformation

VideoManagerInformation LaneAndObjectDetection::VideoManager::m_videoManagerInformation
private

The VideoManagerInformation struct containing all video manager-related information.

Definition at line 234 of file VideoManager.hpp.

◆ m_saveOutputStartTime

std::chrono::time_point<std::chrono::high_resolution_clock> LaneAndObjectDetection::VideoManager::m_saveOutputStartTime
private

The time that the output started to be saved locally.

Definition at line 239 of file VideoManager.hpp.


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