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