Ocean
Loading...
Searching...
No Matches
TestHarrisDetector.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_TESTDETECTOR_TEST_HARRIS_DETECTOR_H
9#define META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_HARRIS_DETECTOR_H
10
12
14
16
17namespace Ocean
18{
19
20namespace Test
21{
22
23namespace TestCV
24{
25
26namespace TestDetector
27{
28
29/**
30 * This class implements a Harris corner detector test.
31 * @ingroup testcvdetector
32 */
33class OCEAN_TEST_CV_DETECTOR_EXPORT TestHarrisDetector
34{
35 public:
36
37 /**
38 * Tests the Harris corner detector.
39 * @param frame Test frame to be used for feature detection, invalid to use a random image
40 * @param testDuration Number of seconds for each test, with range (0, infinity)
41 * @param worker The worker object
42 * @param selector The test selector to filter tests
43 * @return True, if succeeded
44 */
45 static bool test(const Frame& frame, const double testDuration, Worker& worker, const TestSelector& selector);
46
47 /**
48 * Tests the threshold function.
49 * @param testDuration Number of seconds for each test, with range (0, infinity)
50 * @return True, if succeeded
51 */
52 static bool testThreshold(const double testDuration);
53
54 /**
55 * Tests the Harris corner detector with pixel accuracy.
56 * @param testDuration Number of seconds for each test, with range (0, infinity)
57 * @param worker The worker object
58 * @param yFrameTest Optional explicit frame to be used for testing, otherwise a random image will be used
59 * @return True, if succeeded
60 */
61 static bool testPixelAccuracy(const double testDuration, Worker& worker, const Frame& yFrameTest = Frame());
62
63 /**
64 * Tests the Harris corner detector with pixel accuracy for a frame with one rectangle.
65 * @param width The width of the frame in pixel, with range [20, infinity)
66 * @param height The height of the frame in pixel, with range [20, infinity)
67 * @param testDuration Number of seconds for the test, with range (0, infinity)
68 * @param worker The worker object
69 * @return True, if succeeded
70 */
71 static bool testPixelAccuracyCorners(const unsigned int width, const unsigned int height, const double testDuration, Worker& worker);
72
73 /**
74 * Tests the Harris corner detector with sub-pixel accuracy.
75 * @param testDuration Number of seconds for each test, with range (0, infinity)
76 * @param worker The worker object
77 * @param yFrameTest Optional explicit frame to be used for testing, otherwise a random image will be used
78 * @return True, if succeeded
79 */
80 static bool testSubPixelAccuracy(const double testDuration, Worker& worker, const Frame& yFrameTest = Frame());
81
82 /**
83 * Tests the corner detection function in a sub-frame.
84 * @param testDuration Number of seconds for each test, with range (0, infinity)
85 * @param worker The worker object
86 * @param yFrameTest Optional explicit frame to be used for testing, otherwise a random image will be used
87 * @return True, if succeeded
88 */
89 static bool testSubFrameDetection(const double testDuration, Worker& worker, const Frame& yFrameTest = Frame());
90
91 /**
92 * Tests the precise corner detection function is a hard-coded image.
93 * @param testDuration Number of seconds for each test, with range (0, infinity)
94 * @param worker The worker object
95 * @return True, if succeeded
96 */
97 static bool testPreciseCornerDetection(const double testDuration, Worker& worker);
98
99 /**
100 * Tests the corner detection function in a checkerboard image.
101 * @param testDuration Number of seconds for each test, with range (0, infinity)
102 * @param worker The worker object
103 * @return True, if succeeded
104 */
105 static bool testCheckerboardDetection(const double testDuration, Worker& worker);
106
107 /**
108 * Tests the Harris response for a single pixel.
109 * @param testDuration Number of seconds for each test, with range (0, infinity)
110 * @param worker The worker object
111 * @return True, if succeeded
112 */
113 static bool testHarrisVotePixel(const double testDuration, Worker& worker);
114
115 /**
116 * Tests the Harris response for an entire frame.
117 * @param testDuration Number of seconds for each test, with range (0, infinity)
118 * @param worker The worker object
119 * @param yFrameTest Optional explicit frame to be used for testing, otherwise a random image will be used
120 * @return True, if succeeded
121 */
122 static bool testHarrisVoteFrame(const double testDuration, Worker& worker, const Frame& yFrameTest = Frame());
123
124 private:
125
126 /**
127 * Validates the Harris corner detector with pixel accuracy.
128 * @param yFrame Original gray scale frame to be used for feature detection, must be valid
129 * @param threshold Harris feature detection threshold
130 * @param features The features for which the accuracy will be validated
131 * @return True, if succeeded
132 */
133 static bool validatePixelAccuracy(const Frame& yFrame, const unsigned int threshold, const CV::Detector::HarrisCorners& features);
134
135 /**
136 * Determines the horizontal gradient (Sobel response) at a given position.
137 * @param yFrame The frame in which the gradient will be determined, must be valid
138 * @param x Horizontal position in pixel, with range [1, width - 1)
139 * @param y Vertical position in pixel, with range [1, height - 1)
140 * @return Resulting horizontal response
141 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
142 */
143 template <bool tRoundedDivision>
144 static int horizontalGradient(const Frame& yFrame, const unsigned int x, const unsigned int y);
145
146 /**
147 * Determines the vertical gradient (Sobel response) at a given position.
148 * @param yFrame The frame in which the gradient will be determined, must be valid
149 * @param x Horizontal position in pixel, with range [1, width - 1)
150 * @param y Vertical position in pixel, with range [1, height - 1)
151 * @return Resulting vertical response
152 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
153 */
154 template <bool tRoundedDivision>
155 static int verticalGradient(const Frame& yFrame, const unsigned int x, const unsigned int y);
156
157 /**
158 * Determines the Harris vote for a given point in a 3x3 neighborhood.
159 * @param yFrame The frame in which the Harris corner vote is determined, must be valid
160 * @param x Horizontal position with range [2, width - 2)
161 * @param y Vertical position with range [2, height - 2)
162 * @return Resulting Harris vote
163 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
164 */
165 template <bool tRoundedDivision>
166 static int harrisVote3x3(const Frame& yFrame, const unsigned int x, const unsigned int y);
167
168 /**
169 * Sorts two Harris corner objects.
170 * @param a First object
171 * @param b Second object
172 * @return True, if the first object is lesser than the second object
173 */
175
176 /**
177 * Sorts two positions so that the y-position is the major sorting criterion and the x-position is the minor sorting criterion.
178 * @param positionA First position
179 * @param positionB Second position
180 * @return True, if the first position is lesser than the second position
181 */
182 static bool sortPosition(const Vector2& positionA, const Vector2& positionB);
183
184 /**
185 * Performs a rounded division of integer values.
186 * @param value The nominator, with range (-infinity, infinity)
187 * @param denominator The denominator, with range [1, infinity)
188 * @return The rounded result of the division
189 */
190 static inline int roundedDivision(const int value, const unsigned int denominator);
191};
192
193inline int TestHarrisDetector::roundedDivision(const int value, const unsigned int denominator)
194{
195 ocean_assert(denominator != 0);
196
197 if (value >= 0)
198 {
199 return (value + int(denominator / 2u)) / int(denominator);
200 }
201 else
202 {
203 return (value - int(denominator / 2u)) / int(denominator);
204 }
205}
206
207}
208
209}
210
211}
212
213}
214
215#endif // META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_HARRIS_DETECTOR_H
This class implements a Harris corner.
Definition HarrisCorner.h:37
This class implements Ocean's image class.
Definition Frame.h:1879
This class implements a Harris corner detector test.
Definition TestHarrisDetector.h:34
static bool testPixelAccuracyCorners(const unsigned int width, const unsigned int height, const double testDuration, Worker &worker)
Tests the Harris corner detector with pixel accuracy for a frame with one rectangle.
static bool sortPosition(const Vector2 &positionA, const Vector2 &positionB)
Sorts two positions so that the y-position is the major sorting criterion and the x-position is the m...
static bool testSubFrameDetection(const double testDuration, Worker &worker, const Frame &yFrameTest=Frame())
Tests the corner detection function in a sub-frame.
static bool validatePixelAccuracy(const Frame &yFrame, const unsigned int threshold, const CV::Detector::HarrisCorners &features)
Validates the Harris corner detector with pixel accuracy.
static bool testHarrisVoteFrame(const double testDuration, Worker &worker, const Frame &yFrameTest=Frame())
Tests the Harris response for an entire frame.
static bool testThreshold(const double testDuration)
Tests the threshold function.
static bool testSubPixelAccuracy(const double testDuration, Worker &worker, const Frame &yFrameTest=Frame())
Tests the Harris corner detector with sub-pixel accuracy.
static int verticalGradient(const Frame &yFrame, const unsigned int x, const unsigned int y)
Determines the vertical gradient (Sobel response) at a given position.
static bool testHarrisVotePixel(const double testDuration, Worker &worker)
Tests the Harris response for a single pixel.
static int horizontalGradient(const Frame &yFrame, const unsigned int x, const unsigned int y)
Determines the horizontal gradient (Sobel response) at a given position.
static bool testPreciseCornerDetection(const double testDuration, Worker &worker)
Tests the precise corner detection function is a hard-coded image.
static bool testPixelAccuracy(const double testDuration, Worker &worker, const Frame &yFrameTest=Frame())
Tests the Harris corner detector with pixel accuracy.
static bool testCheckerboardDetection(const double testDuration, Worker &worker)
Tests the corner detection function in a checkerboard image.
static bool sortHarris(const CV::Detector::HarrisCorner &a, const CV::Detector::HarrisCorner &b)
Sorts two Harris corner objects.
static int roundedDivision(const int value, const unsigned int denominator)
Performs a rounded division of integer values.
Definition TestHarrisDetector.h:193
static int harrisVote3x3(const Frame &yFrame, const unsigned int x, const unsigned int y)
Determines the Harris vote for a given point in a 3x3 neighborhood.
static bool test(const Frame &frame, const double testDuration, Worker &worker, const TestSelector &selector)
Tests the Harris corner detector.
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
std::vector< HarrisCorner > HarrisCorners
Definition of a vector holding Harris corners.
Definition HarrisCorner.h:30
The namespace covering the entire Ocean framework.
Definition Accessor.h:15