-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageStatistics.h
More file actions
126 lines (103 loc) · 6.6 KB
/
Copy pathImageStatistics.h
File metadata and controls
126 lines (103 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (C) 2025: Arizona Board of Regents on Behalf of the University of Arizona
*/
/**
* @file ImageStatistics.h
* @brief Apache Strap-Down Pilotage Render/Image Statistics classes header file.
*
* @author ReliaSolve.
* @date January 23, 2025.
*/
#pragma once
#include <vector>
#include <string>
#include <memory>
#include <mutex>
#include <atomic>
#include <CameraRenderInfo.h>
namespace asdp {
namespace render {
// Forward declaration to avoid #include loop.
class Display;
namespace imageStatistics {
/// @brief Class that computes the mean and standard deviation of pixel values for an image.
class MeanStd {
public:
/// @brief Construct the mean and standard deviation calculator.
/// @details The caller must have a valid OpenGL context on the calling thread when calling any of the
/// functions in this class, including the constructor. This context must have had glewInit() called on it.
/// @param camera Camera to use for the image.
MeanStd(std::shared_ptr<CameraRenderInfo> camera);
/// @brief Virtual destructor so that proper deconstruction happens on pointers.
virtual ~MeanStd() = default;
/// @brief Compute the mean and standard deviation of the pixel values in the image.
/// @details This function will lock the most-recent image from the camera and compute the mean and
/// standard deviation of the pixel values in the image.
/// @param [out] mean The mean of the pixel values in the image.
/// @param [out] stddev The standard deviation of the pixel values in the image.
/// @return Empty string on success, error description on failure.
std::string Compute(double &mean, double &stddev) const;
/// @brief Get the status of the constructor.
/// @return An empty string on success or an error message on failure.
std::string GetConstructorStatus() const { return m_constructorStatus; }
/// @brief Test function that returns an empty string on success or an error message on failure.
static std::string Test();
/// @brief Test function that returns the time to compute the mean and standard deviation of a single image.
/// @details It computes the mean and standard deviation over many images and returns the average time to compute
/// the mean and standard deviation of a single image.
/// @param width Width of the image to test.
/// @param height Height of the image to test.
/// @return Time in seconds to compute the mean and standard deviation of a single image.
static float SpeedTestSingleCalculation(uint16_t width, uint16_t height);
protected:
std::string m_constructorStatus; ///< Status of the constructor.
class MeanStdImpl; ///< Forward declaration of the implementation class.
std::unique_ptr<MeanStdImpl> m_impl; ///< Pointer to the implementation class.
};
/// @brief Class that computes the mean and standard deviation of pixel values for a set of images.
class MeanStdGroup {
public:
/// @brief Construct the mean and standard deviation calculator for a set of images.
/// @details The caller must have a valid OpenGL context on the calling thread when calling any of the
/// functions in this class, including the constructor. This context must have had glewInit() called on it.
/// This class will start a thread that updates the estimated values on one camera at a time at the
/// specified interval. The thread will run until the destructor is called.
/// It updates its internal mean and standard deviation values at the specified interval in a thread-safe
/// manner.
/// @param cameras Cameras to use for the images.
/// @param display Display to borrow the OpenGL context from.
/// @param updateInterval Interval in seconds to update the mean and standard deviation values. One camera
/// will be updated at each interval in a round-robin fashion, so it will take as many intervals as there
/// are cameras to complete a totally new estimate. This is done incrementally, using N-1 old camera values
/// along with the new value each interval.
MeanStdGroup(std::vector< std::shared_ptr<CameraRenderInfo> > cameras,
std::shared_ptr<Display> display,
double updateInterval = 1.0/60);
/// @brief Virtual destructor so that proper deconstruction happens on pointers.
/// @details This will stop the thread that updates the mean and standard deviation values.
virtual ~MeanStdGroup();
/// @brief Get the mean and standard deviation of the pixel values in the images.
/// @param [out] mean The mean of the pixel values in the images.
/// @param [out] stddev The standard deviation of the pixel values in the images.
/// @return Empty string on success, error description on failure.
std::string GetMeanStd(double &mean, double &stddev) const;
/// @brief Test function that returns an empty string on success or an error message on failure.
static std::string Test();
protected:
std::vector< std::shared_ptr<CameraRenderInfo> > m_cameras; ///< Cameras to use for the images.
std::shared_ptr<Display> m_display; ///< Display to borrow the OpenGL context from.
double m_updateInterval; ///< Interval in seconds to update the mean and standard deviation values.
std::string m_status; ///< Status filled in by the constructor and other methods.
// Maintain vectors of values, one per camera. These are initialized as they are read from the cameras
// and then overwritten when all cameras have been read.
mutable std::mutex m_mutex; ///< Mutex to protect the mean and standard deviation vectors.
std::vector< std::shared_ptr<MeanStd> > m_meanStds; ///< Mean and standard deviation calculators for each camera.
std::vector<double> m_means; ///< Current estimated mean of the pixel values in each image.
std::vector<double> m_stds; ///< Current estimated standard deviation of the pixel values in each image.
std::thread m_updateThread; ///< Thread that updates the mean and standard deviation values.
void UpdateThread(); ///< Thread function that updates the mean and standard deviation values.
std::atomic_bool m_stopThread; ///< Flag to stop the thread that updates the mean and standard deviation values.
};
} // namespace imageStatistics
} // namespace render
} // namespace asdp