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
13#include "ocean/base/Frame.h"
14#include "ocean/base/Worker.h"
15
17
18namespace Ocean
19{
20
21namespace Test
22{
23
24namespace TestCV
25{
26
27/**
28 * This class tests the implementation of the NonMaximumSuppression class.
29 * @ingroup testcv
30 */
31class OCEAN_TEST_CV_EXPORT TestNonMaximumSuppression
32{
33 protected:
34
35 /**
36 * Definition of a location combining a strength parameter.
37 */
39
40 /**
41 * Definition of a vector holding locations.
42 */
43 typedef std::vector<StrengthPosition> StrengthPositions;
44
45 /**
46 * Definition of a set holding locations.
47 */
48 typedef std::set<StrengthPosition> StrengthPositionSet;
49
50 public:
51
52 /**
53 * Tests the entire functionality.
54 * @param width The width of the test frame in pixel, with range [3, infinity)
55 * @param height The height of the test frame in pixel, with range [3, infinity)
56 * @param testDuration Number of seconds for each test, with range (0, infinity)
57 * @param worker The worker object
58 * @return True, if succeeded
59 */
60 static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
61
62 /**
63 * Tests the non maximum suppression within a frame.
64 * @param width The width of the test frame in pixel, with range [3, infinity)
65 * @param height The height of the test frame in pixel, with range [3, infinity)
66 * @param subFrameWidth The width of the actual area of application, with range [2, width]
67 * @param subFrameHeight The height of the actual area of application, with range [2, height]
68 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
69 * @param testDuration Number of seconds for each test, with range (0, infinity)
70 * @param worker The worker object
71 * @return True, if succeeded
72 */
73 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);
74
75 /**
76 * Tests the non maximum suppression within a dataset of strength positions.
77 * @param testDuration Number of seconds for each test, with range (0, infinity)
78 * @return True, if succeeded
79 */
80 static bool testSuppressionInStrengthPositions(const double testDuration);
81
82 /**
83 * Tests the non maximum suppression within a dataset of strength positions.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @return True, if succeeded
86 * @tparam TCoordinate The data type of a scalar coordinate
87 * @tparam TStrength The data type of the strength parameter
88 */
89 template <typename TCoordinate, typename TStrength>
90 static bool testSuppressionInStrengthPositions(const double testDuration);
91
92 /**
93 * Tests the 1D precise peak location function.
94 * @return True, if succeeded
95 * @tparam T The data type of the scalar to be used, either 'float' or 'double'
96 */
97 template <typename T>
99
100 /**
101 * Tests the 2D precise peak location function.
102 * @return True, if succeeded
103 * @tparam T The data type of the scalar to be used, either 'float' or 'double'
104 */
105 template <typename T>
107
108 protected:
109
110 /**
111 * Creates a test frame with artificial feature points.
112 * @param yFrame The frame to which the feature points will be added, must have pixel format FORMAT_Y8, must be valid
113 * @param features The number of feature points to create, with range [0, infinity)
114 * @param featurePointStrength The strength of the feature points to create, with range [1, 255]
115 */
116 static void createFeaturePoints(Frame& yFrame, const unsigned int features, const uint8_t featurePointStrength = 255u);
117
118 /**
119 * Determines the locations of the extrema by a standard implementation.
120 * @param yFrame The frame providing the feature points, with pixel format FORMAT_Y8, must be valid
121 * @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]
122 * @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]
123 * @param subRegionWidth The width of the sub-region in which the points will be determined, with range [width - subRegionLeft]
124 * @param subRegionHeight The height of the sub-region in which the points will be determined, with range [height - subRegionTop]
125 * @param minimalThreshold The minimal value a pixel must have to count as feature candidate
126 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
127 * @param worker Optional worker object to distribute the computation
128 * @return The resulting locations
129 */
130 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);
131
132 /**
133 * Determines the locations of the extrema by a standard implementation.
134 * @param yFrame The frame providing the feature points, with pixel format FORMAT_Y8, must be valid
135 * @param minimalThreshold The minimal value a pixel must have to count as feature candidate
136 * @param strictMaximum True, to search for a strict maximum (larger than all eight neighbors); False, to allow equal values in the upper left neighborhood
137 * @param lock Optional lock which must be defined if this function is executed on several threads in parallel
138 * @param locations The resulting locations in pixel coordinates
139 * @param firstColumn The first column to be handled, with range [1, width - 2]
140 * @param numberColumns The number of columns to be handled, with range [1, width - firstColumn - 1]
141 * @param firstRow The first row to be handled, with range [1, height - 2]
142 * @param numberRows The number of rows to be handled, with range [1, height - firstRow - 1]
143 */
144 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);
145};
146
147inline 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)
148{
149 ocean_assert(yFrame.isValid() && yFrame.pixelFormat() == FrameType::FORMAT_Y8);
150 ocean_assert(subRegionLeft + subRegionWidth <= yFrame.width() && subRegionTop + subRegionHeight <= yFrame.height());
151
152 const unsigned int firstColumn = std::max(1u, subRegionLeft);
153 const unsigned int firstRow = std::max(1u, subRegionTop);
154
155 const unsigned int endColumn = std::min(subRegionLeft + subRegionWidth, yFrame.width() - 1u);
156 const unsigned int endRow = std::min(subRegionTop + subRegionHeight, yFrame.height() - 1u);
157
158 const unsigned int numberColumns = endColumn - firstColumn;
159 const unsigned int numberRows = endRow - firstRow;
160
161 StrengthPositions result;
162
163 if (worker)
164 {
165 Lock lock;
166 worker->executeFunction(Worker::Function::createStatic(&determineFeaturePointsSubset, &yFrame, minimalThreshold, strictMaximum, &lock, &result, firstColumn, numberColumns, 0u, 0u), firstRow, numberRows);
167 }
168 else
169 {
170 determineFeaturePointsSubset(&yFrame, minimalThreshold, strictMaximum, nullptr, &result, firstColumn, numberColumns, firstRow, numberRows);
171 }
172
173 return result;
174}
175
176}
177
178}
179
180}
181
182#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:51
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:2876
This class implements Ocean's image class.
Definition Frame.h:1808
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4528
@ 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:3170
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
This class implements a recursive lock object.
Definition Lock.h:31
This class tests the implementation of the NonMaximumSuppression class.
Definition TestNonMaximumSuppression.h:32
std::vector< StrengthPosition > StrengthPositions
Definition of a vector holding locations.
Definition TestNonMaximumSuppression.h:43
CV::NonMaximumSuppression< uint8_t >::StrengthPosition< int, uint8_t > StrengthPosition
Definition of a location combining a strength parameter.
Definition TestNonMaximumSuppression.h:38
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.
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.
static bool test(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the entire functionality.
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.
std::set< StrengthPosition > StrengthPositionSet
Definition of a set holding locations.
Definition TestNonMaximumSuppression.h:48
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:147
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 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