Lane and Object Detection
Using OpenCV and YOLOv7
Loading...
Searching...
No Matches
Performance.cpp
1#include <chrono>
2#include <cstdint>
3#include <string>
4#include <vector>
5
6#include "helpers/Globals.hpp"
7
8#include "helpers/Performance.hpp"
9
11{
13 m_performanceInformation({.m_averageFramesPerSecond = 0, .m_currentFramesPerSecond = 0})
14 {}
15
17 {
18 m_startTime = std::chrono::high_resolution_clock::now();
19 }
20
22 {
23 const uint32_t FRAME_TIME = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - m_startTime).count();
24
25 m_frameTimes.push_back(FRAME_TIME);
26
27 m_performanceInformation.m_currentFramesPerSecond = Globals::G_MICROSECONDS_IN_SECOND / FRAME_TIME;
28
29 // Calculate the average FPS as a running average
30 const double FRAME_COUNT = static_cast<double>(m_frameTimes.size());
31 m_performanceInformation.m_averageFramesPerSecond = ((m_performanceInformation.m_averageFramesPerSecond * (FRAME_COUNT - 1)) + m_performanceInformation.m_currentFramesPerSecond) / FRAME_COUNT;
32 }
33
38
39 std::vector<uint32_t> Performance::GetFrameTimes()
40 {
41 return m_frameTimes;
42 }
43
45 {
47 }
48
50 {
51 return static_cast<uint32_t>(Globals::G_MICROSECONDS_IN_SECOND);
52 }
53
55 {
56 m_frameTimes.clear();
57 m_performanceInformation = {.m_averageFramesPerSecond = 0, .m_currentFramesPerSecond = 0};
58 }
59}
PerformanceInformation GetInformation()
Get the PerformanceInformation struct.
Performance()
Constructs a new Performance object.
std::vector< uint32_t > GetFrameTimes()
Get the times to compute each and every frame.
static std::string GetTimeUnit()
Get the time unit for the frame times.
std::chrono::time_point< std::chrono::high_resolution_clock > m_startTime
The time the internal timer was started within StartTimer().
static uint32_t GetTimeUnitConversion()
Get the divisor needed to convert the frame times to seconds.
PerformanceInformation m_performanceInformation
The PerformanceInformation struct containing all performance-related information.
void ClearPerformanceInformation()
Clears all performance-related information.
void EndTimer()
End the internal timer.
void StartTimer()
Start the internal timer.
std::vector< uint32_t > m_frameTimes
The frame times that have been measured.
static const double G_MICROSECONDS_IN_SECOND
Conversion between time units.
Definition Globals.hpp:166
static const std::string G_TIME_UNIT
Time unit for performance-related frame times.
Definition Globals.hpp:161
Contains all Lane-and-Object-Detection objects.
The information needed by FrameBuilder to update frame with performance information.