Ocean
Loading...
Searching...
No Matches
TestNonMaximumSuppression.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_TEST_TESTCV_TEST_NON_MAXIMUM_SUPPRESSION_H
9#define META_OCEAN_TEST_TESTCV_TEST_NON_MAXIMUM_SUPPRESSION_H
10
12
14
15#include "ocean/base/Frame.h"
16#include "ocean/base/Worker.h"
17
19
20namespace Ocean
21{
22
23namespace Test
24{
25
26namespace TestCV
27{
28
29/**
30 * This class tests the implementation of the NonMaximumSuppression class.
31 * @ingroup testcv
32 */
33class OCEAN_TEST_CV_EXPORT TestNonMaximumSuppression
34{
35 protected:
36
37 /**
38 * Definition of a location combining a strength parameter.
39 */
41
42 /**
43 * Definition of a vector holding locations.
44 */
45 using StrengthPositions = std::vector<StrengthPosition>;
46
47 /**
48 * Definition of a set holding locations.
49 */
50 using StrengthPositionSet = std::set<StrengthPosition>;
51
52 public:
53
54 /**
55 * Tests the entire functionality.
56 * @param width The width of the test frame in pixel, with range [3, infinity)
57 * @param height The height of the test frame in pixel, with range [3, infinity)
58 * @param testDuration Number of seconds for each test, with range (0, infinity)
59 * @param worker The worker object
60 * @param selector Test selector for filtering sub-tests; default runs all tests
61 * @return True, if succeeded
62 */
63 static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker, const TestSelector& selector = TestSelector());
64
65 /**
66 * Tests the non maximum suppression within a frame.
67 * @param width The width of the test frame in pixel, with range [3, infinity)
68 * @param height The height of the test frame in pixel, with range [3, infinity)
69 * @param subFrameWidth The width of the actual area of application, with range [2, width]
70 * @param subFrameHeight The height of the actual area of application, with range [2, height]
71 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
72 * @param testDuration Number of seconds for each test, with range (0, infinity)
73 * @param worker The worker object
74 * @return True, if succeeded
75 */
76 static bool testSuppressionInFrame(const unsigned int width, const unsigned int height, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const bool strictMaximum, const double testDuration, Worker& worker);
77
78 /**
79 * Tests the non maximum suppression within a dataset of strength positions.
80 * @param testDuration Number of seconds for each test, with range (0, infinity)
81 * @return True, if succeeded
82 */
83 static bool testSuppressionInStrengthPositions(const double testDuration);
84
85 /**
86 * Tests the non maximum suppression within a dataset of strength positions.
87 * @param testDuration Number of seconds for each test, with range (0, infinity)
88 * @return True, if succeeded
89 * @tparam TCoordinate The data type of a scalar coordinate
90 * @tparam TStrength The data type of the strength parameter
91 */
92 template <typename TCoordinate, typename TStrength>
93 static bool testSuppressionInStrengthPositions(const double testDuration);
94
95 /**
96 * Tests the 1D precise peak location function.
97 * @return True, if succeeded
98 * @tparam T The data type of the scalar to be used, either 'float' or 'double'
99 */
100 template <typename T>
102
103 /**
104 * Tests the 2D precise peak location function.
105 * @return True, if succeeded
106 * @tparam T The data type of the scalar to be used, either 'float' or 'double'
107 */
108 template <typename T>
110
111 protected:
112
113 /**
114 * Creates a test frame with artificial feature points.
115 * @param yFrame The frame to which the feature points will be added, must have pixel format FORMAT_Y8, must be valid
116 * @param features The number of feature points to create, with range [0, infinity)
117 * @param featurePointStrength The strength of the feature points to create, with range [1, 255]
118 */
119 static void createFeaturePoints(Frame& yFrame, const unsigned int features, const uint8_t featurePointStrength = 255u);
120
121 /**
122 * Determines the locations of the extrema by a standard implementation.
123 * @param yFrame The frame providing the feature points, with pixel format FORMAT_Y8, must be valid
124 * @param subRegionLeft The left location of the upper left corner of the sub-region in which the points will be determined, with range [0, width - 1]
125 * @param subRegionTop The top location of the upper left corner of the sub-region in which the points will be determined, with range [0, height - 1]
126 * @param subRegionWidth The width of the sub-region in which the points will be determined, with range [width - subRegionLeft]
127 * @param subRegionHeight The height of the sub-region in which the points will be determined, with range [height - subRegionTop]
128 * @param minimalThreshold The minimal value a pixel must have to count as feature candidate
129 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
130 * @param worker Optional worker object to distribute the computation
131 * @return The resulting locations
132 */
133 static inline StrengthPositions determineFeaturePoints(const Frame& yFrame, const unsigned int subRegionLeft, const unsigned int subRegionTop, const unsigned int subRegionWidth, const unsigned int subRegionHeight, const uint8_t minimalThreshold, const bool strictMaximum, Worker* worker = nullptr);
134
135 /**
136 * Determines the locations of the extrema by a standard implementation.
137 * @param yFrame The frame providing the feature points, with pixel format FORMAT_Y8, must be valid
138 * @param minimalThreshold The minimal value a pixel must have to count as feature candidate
139 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
140 * @param lock Optional lock which must be defined if this function is executed on several threads in parallel
141 * @param locations The resulting locations in pixel coordinates
142 * @param firstColumn The first column to be handled, with range [1, width - 2]
143 * @param numberColumns The number of columns to be handled, with range [1, width - firstColumn - 1]
144 * @param firstRow The first row to be handled, with range [1, height - 2]
145 * @param numberRows The number of rows to be handled, with range [1, height - firstRow - 1]
146 */
147 static void determineFeaturePointsSubset(const Frame* yFrame, const uint8_t minimalThreshold, const bool strictMaximum, Lock* lock, StrengthPositions* locations, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows);
148};
149
150inline TestNonMaximumSuppression::StrengthPositions TestNonMaximumSuppression::determineFeaturePoints(const Frame& yFrame, const unsigned int subRegionLeft, const unsigned int subRegionTop, const unsigned int subRegionWidth, const unsigned int subRegionHeight, const uint8_t minimalThreshold, const bool strictMaximum, Worker* worker)
151{
152 ocean_assert(yFrame.isValid() && yFrame.pixelFormat() == FrameType::FORMAT_Y8);
153 ocean_assert(subRegionLeft + subRegionWidth <= yFrame.width() && subRegionTop + subRegionHeight <= yFrame.height());
154
155 const unsigned int firstColumn = std::max(1u, subRegionLeft);
156 const unsigned int firstRow = std::max(1u, subRegionTop);
157
158 const unsigned int endColumn = std::min(subRegionLeft + subRegionWidth, yFrame.width() - 1u);
159 const unsigned int endRow = std::min(subRegionTop + subRegionHeight, yFrame.height() - 1u);
160
161 const unsigned int numberColumns = endColumn - firstColumn;
162 const unsigned int numberRows = endRow - firstRow;
163
164 StrengthPositions result;
165
166 if (worker)
167 {
168 Lock lock;
169 worker->executeFunction(Worker::Function::createStatic(&determineFeaturePointsSubset, &yFrame, minimalThreshold, strictMaximum, &lock, &result, firstColumn, numberColumns, 0u, 0u), firstRow, numberRows);
170 }
171 else
172 {
173 determineFeaturePointsSubset(&yFrame, minimalThreshold, strictMaximum, nullptr, &result, firstColumn, numberColumns, firstRow, numberRows);
174 }
175
176 return result;
177}
178
179}
180
181}
182
183}
184
185#endif // META_OCEAN_TEST_TESTCV_TEST_NON_MAXIMUM_SUPPRESSION_H
This class extends a 2D position by a third parameter storing a strength value.
Definition NonMaximumSuppression.h:52
static Caller< void > createStatic(typename StaticFunctionPointerMaker< void, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass, NullClass >::Type function)
Creates a new caller container for a static function with no function parameter.
Definition Caller.h:2877
This class implements Ocean's image class.
Definition Frame.h:1879
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4612
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition Frame.h:594
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3241
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3251
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3246
This class implements a recursive lock object.
Definition Lock.h:31
This class tests the implementation of the NonMaximumSuppression class.
Definition TestNonMaximumSuppression.h:34
static bool testSuppressionInFrame(const unsigned int width, const unsigned int height, const unsigned int subFrameWidth, const unsigned int subFrameHeight, const bool strictMaximum, const double testDuration, Worker &worker)
Tests the non maximum suppression within a frame.
std::vector< StrengthPosition > StrengthPositions
Definition of a vector holding locations.
Definition TestNonMaximumSuppression.h:45
static void determineFeaturePointsSubset(const Frame *yFrame, const uint8_t minimalThreshold, const bool strictMaximum, Lock *lock, StrengthPositions *locations, const unsigned int firstColumn, const unsigned int numberColumns, const unsigned int firstRow, const unsigned int numberRows)
Determines the locations of the extrema by a standard implementation.
std::set< StrengthPosition > StrengthPositionSet
Definition of a set holding locations.
Definition TestNonMaximumSuppression.h:50
static bool testSuppressionInStrengthPositions(const double testDuration)
Tests the non maximum suppression within a dataset of strength positions.
static bool testDeterminePrecisePeakLocation1()
Tests the 1D precise peak location function.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker, const TestSelector &selector=TestSelector())
Tests the entire functionality.
static StrengthPositions determineFeaturePoints(const Frame &yFrame, const unsigned int subRegionLeft, const unsigned int subRegionTop, const unsigned int subRegionWidth, const unsigned int subRegionHeight, const uint8_t minimalThreshold, const bool strictMaximum, Worker *worker=nullptr)
Determines the locations of the extrema by a standard implementation.
Definition TestNonMaximumSuppression.h:150
static void createFeaturePoints(Frame &yFrame, const unsigned int features, const uint8_t featurePointStrength=255u)
Creates a test frame with artificial feature points.
static bool testSuppressionInStrengthPositions(const double testDuration)
Tests the non maximum suppression within a dataset of strength positions.
static bool testDeterminePrecisePeakLocation2()
Tests the 2D precise peak location function.
This class implements a test selector that parses test function strings and determines which tests sh...
Definition TestSelector.h:51
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
bool executeFunction(const Function &function, const unsigned int first, const unsigned int size, const unsigned int firstIndex=(unsigned int)(-1), const unsigned int sizeIndex=(unsigned int)(-1), const unsigned int minimalIterations=1u, const unsigned int threadIndex=(unsigned int)(-1))
Executes a callback function separable by two function parameters.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15