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 corner detection function in a checkerboard 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 testCheckerboardDetection(const double testDuration, Worker& worker);
98
99 /**
100 * Tests the Harris response for a single pixel.
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 testHarrisVotePixel(const double testDuration, Worker& worker);
106
107 /**
108 * Tests the Harris response for an entire frame.
109 * @param testDuration Number of seconds for each test, with range (0, infinity)
110 * @param worker The worker object
111 * @param yFrameTest Optional explicit frame to be used for testing, otherwise a random image will be used
112 * @return True, if succeeded
113 */
114 static bool testHarrisVoteFrame(const double testDuration, Worker& worker, const Frame& yFrameTest = Frame());
115
116 private:
117
118 /**
119 * Validates the Harris corner detector with pixel accuracy.
120 * @param yFrame Original gray scale frame to be used for feature detection, must be valid
121 * @param threshold Harris feature detection threshold
122 * @param features The features for which the accuracy will be validated
123 * @return True, if succeeded
124 */
125 static bool validatePixelAccuracy(const Frame& yFrame, const unsigned int threshold, const CV::Detector::HarrisCorners& features);
126
127 /**
128 * Determines the horizontal gradient (Sobel response) at a given position.
129 * @param yFrame The frame in which the gradient will be determined, must be valid
130 * @param x Horizontal position in pixel, with range [1, width - 1)
131 * @param y Vertical position in pixel, with range [1, height - 1)
132 * @return Resulting horizontal response
133 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
134 */
135 template <bool tRoundedDivision>
136 static int horizontalGradient(const Frame& yFrame, const unsigned int x, const unsigned int y);
137
138 /**
139 * Determines the vertical gradient (Sobel response) at a given position.
140 * @param yFrame The frame in which the gradient will be determined, must be valid
141 * @param x Horizontal position in pixel, with range [1, width - 1)
142 * @param y Vertical position in pixel, with range [1, height - 1)
143 * @return Resulting vertical response
144 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
145 */
146 template <bool tRoundedDivision>
147 static int verticalGradient(const Frame& yFrame, const unsigned int x, const unsigned int y);
148
149 /**
150 * Determines the Harris vote for a given point in a 3x3 neighborhood.
151 * @param yFrame The frame in which the Harris corner vote is determined, must be valid
152 * @param x Horizontal position with range [2, width - 2)
153 * @param y Vertical position with range [2, height - 2)
154 * @return Resulting Harris vote
155 * @tparam tRoundedDivision True, to use a rounded division for integers; False, to use a normal division
156 */
157 template <bool tRoundedDivision>
158 static int harrisVote3x3(const Frame& yFrame, const unsigned int x, const unsigned int y);
159
160 /**
161 * Sorts two Harris corner objects.
162 * @param a First object
163 * @param b Second object
164 * @return True, if the first object is lesser than the second object
165 */
167
168 /**
169 * Performs a rounded division of integer values.
170 * @param value The nominator, with range (-infinity, infinity)
171 * @param denominator The denominator, with range [1, infinity)
172 * @return The rounded result of the division
173 */
174 static inline int roundedDivision(const int value, const unsigned int denominator);
175};
176
177inline int TestHarrisDetector::roundedDivision(const int value, const unsigned int denominator)
178{
179 ocean_assert(denominator != 0);
180
181 if (value >= 0)
182 {
183 return (value + int(denominator / 2u)) / int(denominator);
184 }
185 else
186 {
187 return (value - int(denominator / 2u)) / int(denominator);
188 }
189}
190
191}
192
193}
194
195}
196
197}
198
199#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 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 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:177
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