Ocean
TestShapeDetector.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_SHAPE_DETECTOR_H
9 #define META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_SHAPE_DETECTOR_H
10 
12 
13 #include "ocean/base/Frame.h"
14 
16 
17 namespace Ocean
18 {
19 
20 namespace Test
21 {
22 
23 namespace TestCV
24 {
25 
26 namespace TestDetector
27 {
28 
29 /**
30  * This class implements tests for the Shape detector.
31  * @ingroup testcvdetector
32  */
34 {
35  protected:
36 
40 
44 
45  public:
46 
47  /**
48  * Definition of indivdual response types.
49  */
50  enum ResponseType : uint32_t
51  {
52  /// The response is composed of the horizontal and vertical response.
53  RT_HORIZONTAL_AND_VERTICAL = 0u,
54  /// The response is just based on the horizontal response.
55  RT_HORIZONTAL = 1u,
56  /// The response is just based on the vertical response.
57  RT_VERTICAL = 2u,
58  };
59 
60  /**
61  * Definition of individual response visualization types.
62  */
63  enum ResponseVisualization : uint32_t
64  {
65  /// The response values are visualized with linear normalization.
66  RV_LINEAR = 0u,
67  /// The response values are visualized with a logarithmic normalization.
68  RV_LOGARITHMIC = 1u
69  };
70 
71  /**
72  * This class provides the ground truth implementation of the gradient-based T-detector.
73  */
74  class OCEAN_TEST_CV_DETECTOR_EXPORT GradientBasedDetector
75  {
76  public:
77 
78  /**
79  * Definition of individual stategies to determine edge response.
80  */
81  enum EdgeResponseStrategy : uint32_t
82  {
83  /// The edge gradient (vertical and horizontal) is determined between the edge pixel and the direct neighboring pixel.
84  ERS_GRADIENT_TO_NEIGHBOR = 0u,
85  /// The edge gradient (vertical and horizontal) is determine between the edge pixel and the center pixel.
86  ERS_GRADIENT_TO_CENTER = 1u
87  };
88 
89  /**
90  * Definition of individual stategies to handle a minimal edge response.
91  */
92  enum MinimalResponseStrategy : uint32_t
93  {
94  /// The minimal response is ignored.
95  MRS_IGNORE = 0u,
96  /// The minimal response is checked separately across the horizontal and vertical edge responses.
97  MRS_SEPARATE_HORIZONTAL_VERTICAL = 1u,
98  /// The minimal response is checked separately across opposite edges.
99  MRS_SEPARATE_OPPOSITE_SIDE = 2u
100  };
101 
102  /**
103  * Definition of individual penalty usages.
104  */
105  enum PenaltyUsage : uint32_t
106  {
107  /// The penalty is subtracted from the edge response.
108  PU_SUBTRACT = 0u,
109  /// The penalty is used to normalize the edge response (by division).
110  PU_DIVISION = 1u
111  };
112 
113  public:
114 
115  /**
116  * Detects shapes in a given image.
117  * @param yFrame The frame in which the shapes will be detected, must be valid
118  * @param threshold The minimal threshold for a detected shape, with range (0, infinity)
119  * @param responseMultiplicationFactor An explicit post-processing multiplicatio factor for detector responses, with range (0, infinity)
120  * @param lShapes The resulting detected L-shapes
121  * @param tShapes The resulting detected T-shapes
122  * @param xShapes The resulting detected X-shapes
123  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment
124  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
125  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
126  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
127  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
128  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
129  * @param responseType The response type to be used for shape detection
130  * @param penaltyFactor The multiplication factor for the penalty value, with range (0, infinity)
131  * @param minimalEdgeResponse The minimal edge response the detector must create to accept the response as candidate, with range [0, infinity)
132  * @param nonMaximumSupressionRadius The radius which is applied during non-maximum-suppression, with range [1, infinity)
133  * @param edgeResponseStrategy The response strategy for edges which will be applied
134  * @param minimalResponseStrategy The strategy for minimal responses to be applied
135  * @param penaltyUsage The penalty mode to be applied
136  * @param fResponseTopDown Optional resulting detector response image for the top-down detector (not rotated)
137  * @param fResponseBottomUp Optional resulting detector response image for the bottom-up detector (rotated by 180 degree)
138  */
139  static void detectShapes(const Frame& yFrame, const double threshold, const double responseMultiplicationFactor, LShapes& lShapes, TShapes& tShapes, XShapes& xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double penaltyFactor, const unsigned int minimalEdgeResponse, const double nonMaximumSupressionRadius, const EdgeResponseStrategy edgeResponseStrategy, const MinimalResponseStrategy minimalResponseStrategy, const PenaltyUsage penaltyUsage, Frame* fResponseTopDown = nullptr, Frame* fResponseBottomUp = nullptr);
140 
141  /**
142  * Determines the gradient-based T-shape detector response.
143  * @param yFrame The frame in which the detector will be applied, must have pixel format FORMAT_Y8
144  * @param x The horizontal position of the T-shape within the frame, with range [0, yFrame.width())
145  * @param y The vertical position of the T-shape wihtin the frame, with range [0, yFrame.height())
146  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment
147  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
148  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
149  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
150  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
151  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
152  * @param responseType The response type to be used for shape detection
153  * @param penaltyFactor The multiplication factor for the penalty value, with range (0, infinity)
154  * @param minimalEdgeResponse The minimal edge response the detector must create to accept the response as candidate, with range [0, infinity)
155  * @param edgeResponseStrategy The response strategy for edges which will be applied
156  * @param minimalResponseStrategy The strategy for minimal responses to be applied
157  * @param penaltyUsage The penalty mode to be applied
158  * @return The reponse of the T-shape detector
159  */
160  static double tShapeDetectorResponse(const Frame& yFrame, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double penaltyFactor, const unsigned int minimalEdgeResponse, const EdgeResponseStrategy edgeResponseStrategy, const MinimalResponseStrategy minimalResponseStrategy, const PenaltyUsage penaltyUsage);
161  };
162 
163  /**
164  * This class provides the ground truth implementation of the variance-based T-detector.
165  */
166  class OCEAN_TEST_CV_DETECTOR_EXPORT VarianceBasedDetector
167  {
168  public:
169 
170  /**
171  * Definition of individual stategies to determine the gradient response.
172  */
173  enum GradientResponseStrategy : uint32_t
174  {
175  /// The foreground response is based on the maximum absolute difference.
176  GRS_MAX_ABSOLUTE_DIFFERENCE = 0u,
177  /// The foreground response is based on the sum of absolute differences.
178  GRS_SUM_ABSOLUTE_DIFFERENCES = 1u,
179  };
180 
181  /**
182  * Definition of individual band strategies.
183  */
184  enum BandStrategy : uint32_t
185  {
186  /// The band variance is determined based on a joining all band blocks.
187  BS_JOINED = 0u,
188  /// The band variance is determined based on the average variance of all band blocks.
189  BS_SEPARATE_AVERAGE = 1u,
190  /// The band variance is determined based on the maximum variance of all band blocks.
191  BS_SEPARATE_MAX = 2u,
192  /// The band variance is not used.
193  BS_SKIP = 3u
194  };
195 
196  /**
197  * Definition of individual threshold strategies.
198  */
199  enum ThresholdStrategy : uint32_t
200  {
201  /// The threshold value is used as defined.
202  TS_VALUE = 0u,
203  /// The threshold is based on 65% of the sorted top 100 shapes.
204  TS_BASED_ON_TOP_100_65 = 1u,
205  /// The threshold is based on 55% of the sorted top 75 shapes.
206  TS_BASED_ON_TOP_75_55 = 2u,
207  };
208 
209  public:
210 
211  /**
212  * Detects shapes in a given image.
213  * @param yFrame The frame in which the shapes will be detected, must be valid
214  * @param threshold The minimal threshold for a detected shape, with range (0, infinity)
215  * @param responseMultiplicationFactor An explicit post-processing multiplicatio factor for detector responses, with range (0, infinity)
216  * @param lShapes The resulting detected L-shapes
217  * @param tShapes The resulting detected T-shapes
218  * @param xShapes The resulting detected X-shapes
219  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
220  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
221  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
222  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
223  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
224  * @param responseType The response type to be used for shape detection
225  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
226  * @param varianceFactor The multiplication factor for the variance, with range (0, infinity)
227  * @param minimalVariance The minimal variance value used as lower boundary, with range (0, infinity)
228  * @param maximalRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
229  * @param nonMaximumSupressionRadius The radius which is applied during non-maximum-suppression, with range [1, infinity)
230  * @param thresholdStrategy The strategy for thresholding the shapes
231  * @param gradientResponseStrategy The strategy for gradient responses to be applied
232  * @param bandStrategy The strategy how to determine the variances for the bands
233  * @param fResponseTopDown Optional resulting detector response image for the top-down detector (not rotated)
234  * @param fResponseBottomUp Optional resulting detector response image for the bottom-up detector (rotated by 180 degree)
235  */
236  static void detectShapes(const Frame& yFrame, const double threshold, const double responseMultiplicationFactor, LShapes& lShapes, TShapes& tShapes, XShapes& xShapes, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double varianceFactor, const double minimalVariance, const double maximalRatio, const double nonMaximumSupressionRadius, const ThresholdStrategy thresholdStrategy, const GradientResponseStrategy gradientResponseStrategy, const BandStrategy bandStrategy, Frame* fResponseTopDown = nullptr, Frame* fResponseBottomUp = nullptr);
237 
238  /**
239  * Determines the gradient-based T-shape detector response.
240  * @param linedIntegral The lined integral image of the original yFrame, must be valid
241  * @param linedIntegralSquared The lined integral squared image of the original yFrame, must be valid
242  * @param width The width of the original yFrame, in pixel, with range [1, infinity)
243  * @param height The height of the original yFrame, in pixel, with range [1, infinity)
244  * @param x The horizontal location for which the T-shape response will be determined, in pixel, with range [0, width - 1]
245  * @param y The vertical location for which the T-shape response will be determined, in pixel, with range [0, height - 1]
246  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
247  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
248  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
249  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
250  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
251  * @param responseType The response type to be used for shape detection
252  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
253  * @param varianceFactor The multiplication factor for the variance, with range (0, infinity)
254  * @param minimalVariance The minimal variance value used as lower boundary, with range (0, infinity)
255  * @param maximalRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
256  * @param gradientResponseStrategy The strategy for gradient responses to be applied
257  * @param bandStrategy The strategy how to determine the variances for the bands
258  */
259  static double tShapeDetectorResponse(const uint32_t* linedIntegral, const uint64_t* linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double varianceFactor, const double minimalVariance, const double maximalRatio, const GradientResponseStrategy gradientResponseStrategy, const BandStrategy bandStrategy);
260  };
261 
262  /**
263  * This class provides the ground truth implementation of the gradient&variance-based T-detector.
264  * The shape detector has the following geometry:
265  * <pre>
266  * T-shape width
267  * <--------------------------------------->
268  *
269  * --------------------------------------- ^
270  * | | | top band
271  * | | V
272  * ^ |#######################################| ^
273  * | | | |
274  * | | X | | shapeStepSize
275  * | | | |
276  * | |################ ################| V
277  * T-shape | | # # | ^
278  * height | | # # | | bottom band
279  * | -------- # # -------- V
280  * | | # # |
281  * | | # # |
282  * | | # # |
283  * | | # # |
284  * | | # # |
285  * | | # # |
286  * | | # # |
287  * | | # # |
288  * V ---------------------
289  *
290  * X: position of the T-shape
291  * #: edges of the T-shape
292  * </pre>
293  */
294  class OCEAN_TEST_CV_DETECTOR_EXPORT GradientVarianceBasedDetector
295  {
296  public:
297 
298  /**
299  * Definition of individual band strategies.
300  */
301  enum BandStrategy : uint32_t
302  {
303  /// The band variance is not used.
304  BS_SKIP = 0u,
305  /// The band variance is divided.
307  /// The band variance is divided and subtracted.
309  /// Last (exclusive) band strategy value.
310  BS_END
311  };
312 
313  /**
314  * Definition of individual optimization strategies.
315  */
316  enum OptimizationStrategy : uint32_t
317  {
318  /// No optimization.
319  OS_NONE = 0u,
320  /// Applying symmetric responses to allow response recycling, top and bottom band need to be identical, four horizontal response (two top and bottom blocks), vertical blocks have same height.
322  /// Applying symmetric responses to allow response recycling, top and bottom band need to be identical, four horizontal response (two top and bottom blocks), vertical blocks have different height.
324  /// Applying symmetric responses to allow response recycling, top and bottom band need to be identical, two horizontal repsonse (one top and one bottom block), vertical blocks have same height.
326  /// Applying symmetric responses to allow response recycling, top and bottom band need to be identical, two horizontal repsonse (one top and one bottom block), vertical blocks have different height.
328  /// Last (exclusive) optimization strategy value.
329  OS_END
330  };
331 
332  public:
333 
334  /**
335  * Detects standard shapes in a given image.
336  * @param yFrame The frame in which the shapes will be detected, must be valid
337  * @param threshold The minimal threshold for a detected shape, with range (0, infinity)
338  * @param responseMultiplicationFactor An explicit post-processing multiplication factor for detector responses, with range (0, infinity)
339  * @param lShapes The resulting detected L-shapes
340  * @param tShapes The resulting detected T-shapes
341  * @param xShapes The resulting detected X-shapes
342  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment, 0 to accept shapes with both signs
343  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
344  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
345  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
346  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
347  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
348  * @param responseType The response type to be used for shape detection
349  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
350  * @param maximalResponseRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
351  * @param bandStrategy The band strategy to be applied
352  * @param optimizationStrategy The optimization strategy to be applied
353  * @param nonMaximumSupressionRadius The radius which is applied during non-maximum-suppression, with range [1, infinity)
354  * @param fResponseTopDown Optional resulting detector response image for the top-down detector (not rotated)
355  * @param fResponseBottomUp Optional resulting detector response image for the bottom-up detector (rotated by 180 degree)
356  */
357  static void detectShapes(const Frame& yFrame, const double threshold, const double responseMultiplicationFactor, LShapes& lShapes, TShapes& tShapes, XShapes& xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const OptimizationStrategy optimizationStrategy, const double nonMaximumSupressionRadius, Frame* fResponseTopDown = nullptr, Frame* fResponseBottomUp = nullptr);
358 
359  /**
360  * Detects modified shapes in a given image.
361  * The modified shapes do not have a bar-edge roof, but a step-edge roof.
362  * @param yFrame The frame in which the shapes will be detected, must be valid
363  * @param threshold The minimal threshold for a detected shape, with range (0, infinity)
364  * @param responseMultiplicationFactor An explicit post-processing multiplication factor for detector responses, with range (0, infinity)
365  * @param lShapes The resulting detected L-shapes
366  * @param tShapes The resulting detected T-shapes
367  * @param xShapes The resulting detected X-shapes
368  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment, 0 to accept shapes with both signs
369  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
370  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
371  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
372  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
373  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
374  * @param responseType The response type to be used for shape detection
375  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
376  * @param maximalResponseRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
377  * @param bandStrategy The band strategy to be applied
378  * @param nonMaximumSupressionRadius The radius which is applied during non-maximum-suppression, with range [1, infinity)
379  * @param fResponseTopDown Optional resulting detector response image for the top-down detector (not rotated)
380  * @param fResponseBottomUp Optional resulting detector response image for the bottom-up detector (rotated by 180 degree)
381  */
382  static void detectShapesModified(const Frame& yFrame, const double threshold, const double responseMultiplicationFactor, LShapes& lShapes, TShapes& tShapes, XShapes& xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const double nonMaximumSupressionRadius, Frame* fResponseTopDown = nullptr, Frame* fResponseBottomUp = nullptr);
383 
384  /**
385  * Determines the gradient&variance-based T-shape detector response.
386  * @param linedIntegral The lined integral image of the original yFrame, must be valid
387  * @param linedIntegralSquared The lined integral squared image of the original yFrame, must be valid
388  * @param width The width of the original yFrame, in pixel, with range [1, infinity)
389  * @param height The height of the original yFrame, in pixel, with range [1, infinity)
390  * @param x The horizontal location for which the T-shape response will be determined, in pixel, with range [0, width - 1]
391  * @param y The vertical location for which the T-shape response will be determined, in pixel, with range [0, height - 1]
392  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment, 0 to accept shapes with both signs
393  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
394  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
395  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
396  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
397  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
398  * @param responseType The response type to be used for shape detection
399  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
400  * @param maximalResponseRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
401  * @param bandStrategy The band strategy to be applied
402  * @param optimizationStrategy The optimization strategy to be applied
403  * @param horizontalResponse Optional resulting horizontal response
404  * @param verticalResponse Optional vertical horizontal response
405  */
406  static double tShapeDetectorResponse(const uint32_t* linedIntegral, const uint64_t* linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const OptimizationStrategy optimizationStrategy, double* horizontalResponse = nullptr, double* verticalResponse = nullptr);
407 
408  /**
409  * Determines the gradient&variance-based T-shape detector response.
410  * The modified T-shapes do not have a bar-edge roof, but a step-edge roof.
411  * @param linedIntegral The lined integral image of the original yFrame, must be valid
412  * @param linedIntegralSquared The lined integral squared image of the original yFrame, must be valid
413  * @param width The width of the original yFrame, in pixel, with range [1, infinity)
414  * @param height The height of the original yFrame, in pixel, with range [1, infinity)
415  * @param x The horizontal location for which the T-shape response will be determined, in pixel, with range [0, width - 1]
416  * @param y The vertical location for which the T-shape response will be determined, in pixel, with range [0, height - 1]
417  * @param sign The sign of the shape to be detected, -1 for shapes with dark edges and bright environment, 1 for shapes with bright edges and dark environment, 0 to accept shapes with both signs
418  * @param shapeWidth The width of the shapes, in pixel, with range [shapeBottomBand * 2 + shapeStepSize, infinity), must be odd
419  * @param shapeHeight The height of the shapes, in pixel, with range [shapeBottomBand + shapeStepSize, infinity)
420  * @param shapeStepSize The step size of the shapes, in pixel, with range [1, infinity), must be odd
421  * @param shapeTopBand The top band size of the shapes, in pixel, with range [1, infinity)
422  * @param shapeBottomBand The bottom band size of the shapes, in pixel, with range [1, infinity)
423  * @param responseType The response type to be used for shape detection
424  * @param minimalGradient The minimal gradient which is necessary to accept a response, with range [0, 256)
425  * @param maximalResponseRatio The maximal ratio between horizontal and vertical responses to accept a response, with range [1, infinity)
426  * @param bandStrategy The band strategy to be applied
427  * @param horizontalResponse Optional resulting horizontal response
428  * @param verticalResponse Optional vertical horizontal response
429  */
430  static double tShapeDetectorResponseModified(const uint32_t* linedIntegral, const uint64_t* linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, double* horizontalResponse = nullptr, double* verticalResponse = nullptr);
431  };
432 
433  public:
434 
435  /**
436  * Tests the shape detector functions.
437  * @param testDuration Number of seconds for each test, with range (0, infinity)
438  * @return True, if succeeded
439  */
440  static bool test(const double testDuration);
441 
442  /**
443  * Test the gradient-based T-shape detector.
444  * @param testDuration The duration in seconds for which this test will be run, with range (0, infinity)
445  * @return True, if succeeded
446  */
447  static bool testGradientBasedTShapeDetector(const double testDuration);
448 
449  /**
450  * Test the horizontal response of the gradient&variance-based T-shape detector.
451  * @param testDuration The duration in seconds for which this test will be run, with range (0, infinity)
452  * @return True, if succeeded
453  */
454  static bool testGradientVarianceBasedTShapeDetectorHorizontalResponse(const double testDuration);
455 
456  /**
457  * Test the vertical response of the gradient&variance-based T-shape detector.
458  * @param testDuration The duration in seconds for which this test will be run, with range (0, infinity)
459  * @return True, if succeeded
460  */
461  static bool testGradientVarianceBasedTShapeDetectorVerticalResponse(const double testDuration);
462 
463  /**
464  * Test the gradient&variance-based T-shape detector.
465  * @param testDuration The duration in seconds for which this test will be run, with range (0, infinity)
466  * @return True, if succeeded
467  */
468  static bool testGradientVarianceBasedTShapeDetector(const double testDuration);
469 
470  protected:
471 
472  /**
473  * Compares two T-shapes and returns whether the left shape has a higher score.
474  * @param left The left T-shape to compare
475  * @param right The right T-shape to compare
476  * @return True, if so
477  */
478  static inline bool compareTshapes(const TShape& left, const TShape& right);
479 };
480 
481 inline bool TestShapeDetector::compareTshapes(const TShape& left, const TShape& right)
482 {
483  return left.score() > right.score();
484 }
485 
486 } // namespace TestDetector
487 
488 } // namespace TestCV
489 
490 } // namespce Test
491 
492 } // namespace Ocean
493 
494 #endif // META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_SHAPE_DETECTOR_H
This class implements an L-shape element like a corner of a rectangle.
Definition: ShapeDetector.h:175
This class implements a shape detector based on gradients and variance.
Definition: ShapeDetector.h:503
This class implements a T-shape element like a junction connecting two lines, with one line having th...
Definition: ShapeDetector.h:249
Scalar score() const
Returns the sore of this shape.
Definition: ShapeDetector.h:1081
This class implements a X-shape element like a crossing of two lines, with both lines not crossing ne...
Definition: ShapeDetector.h:302
std::vector< LShape > LShapes
Definition of a vector holding L-shape objects.
Definition: ShapeDetector.h:369
std::vector< TShape > TShapes
Definition of a vector holding T-shape objects.
Definition: ShapeDetector.h:374
std::vector< XShape > XShapes
Definition of a vector holding X-shape objects.
Definition: ShapeDetector.h:379
This class implements Ocean's image class.
Definition: Frame.h:1792
This class provides the ground truth implementation of the gradient-based T-detector.
Definition: TestShapeDetector.h:75
MinimalResponseStrategy
Definition of individual stategies to handle a minimal edge response.
Definition: TestShapeDetector.h:93
PenaltyUsage
Definition of individual penalty usages.
Definition: TestShapeDetector.h:106
static void detectShapes(const Frame &yFrame, const double threshold, const double responseMultiplicationFactor, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double penaltyFactor, const unsigned int minimalEdgeResponse, const double nonMaximumSupressionRadius, const EdgeResponseStrategy edgeResponseStrategy, const MinimalResponseStrategy minimalResponseStrategy, const PenaltyUsage penaltyUsage, Frame *fResponseTopDown=nullptr, Frame *fResponseBottomUp=nullptr)
Detects shapes in a given image.
static double tShapeDetectorResponse(const Frame &yFrame, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double penaltyFactor, const unsigned int minimalEdgeResponse, const EdgeResponseStrategy edgeResponseStrategy, const MinimalResponseStrategy minimalResponseStrategy, const PenaltyUsage penaltyUsage)
Determines the gradient-based T-shape detector response.
EdgeResponseStrategy
Definition of individual stategies to determine edge response.
Definition: TestShapeDetector.h:82
This class provides the ground truth implementation of the gradient&variance-based T-detector.
Definition: TestShapeDetector.h:295
static void detectShapesModified(const Frame &yFrame, const double threshold, const double responseMultiplicationFactor, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const double nonMaximumSupressionRadius, Frame *fResponseTopDown=nullptr, Frame *fResponseBottomUp=nullptr)
Detects modified shapes in a given image.
static void detectShapes(const Frame &yFrame, const double threshold, const double responseMultiplicationFactor, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const OptimizationStrategy optimizationStrategy, const double nonMaximumSupressionRadius, Frame *fResponseTopDown=nullptr, Frame *fResponseBottomUp=nullptr)
Detects standard shapes in a given image.
BandStrategy
Definition of individual band strategies.
Definition: TestShapeDetector.h:302
@ BS_SUBTRACT_AND_DIVIDE
The band variance is divided and subtracted.
Definition: TestShapeDetector.h:308
@ BS_DIVIDE
The band variance is divided.
Definition: TestShapeDetector.h:306
static double tShapeDetectorResponse(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, const OptimizationStrategy optimizationStrategy, double *horizontalResponse=nullptr, double *verticalResponse=nullptr)
Determines the gradient&variance-based T-shape detector response.
static double tShapeDetectorResponseModified(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double maximalResponseRatio, const BandStrategy bandStrategy, double *horizontalResponse=nullptr, double *verticalResponse=nullptr)
Determines the gradient&variance-based T-shape detector response.
OptimizationStrategy
Definition of individual optimization strategies.
Definition: TestShapeDetector.h:317
@ OS_SYMMETRIC_RESPONSES_FOUR_HORIZONTAL_DIFFERENT_VERTICAL
Applying symmetric responses to allow response recycling, top and bottom band need to be identical,...
Definition: TestShapeDetector.h:323
@ OS_SYMMETRIC_RESPONSES_TWO_HORIZONTAL_DIFFERENT_VERTICAL
Applying symmetric responses to allow response recycling, top and bottom band need to be identical,...
Definition: TestShapeDetector.h:327
@ OS_SYMMETRIC_RESPONSES_TWO_HORIZONTAL_SAME_VERTICAL
Applying symmetric responses to allow response recycling, top and bottom band need to be identical,...
Definition: TestShapeDetector.h:325
@ OS_SYMMETRIC_RESPONSES_FOUR_HORIZONTAL_SAME_VERTICAL
Applying symmetric responses to allow response recycling, top and bottom band need to be identical,...
Definition: TestShapeDetector.h:321
This class provides the ground truth implementation of the variance-based T-detector.
Definition: TestShapeDetector.h:167
GradientResponseStrategy
Definition of individual stategies to determine the gradient response.
Definition: TestShapeDetector.h:174
ThresholdStrategy
Definition of individual threshold strategies.
Definition: TestShapeDetector.h:200
static void detectShapes(const Frame &yFrame, const double threshold, const double responseMultiplicationFactor, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double varianceFactor, const double minimalVariance, const double maximalRatio, const double nonMaximumSupressionRadius, const ThresholdStrategy thresholdStrategy, const GradientResponseStrategy gradientResponseStrategy, const BandStrategy bandStrategy, Frame *fResponseTopDown=nullptr, Frame *fResponseBottomUp=nullptr)
Detects shapes in a given image.
static double tShapeDetectorResponse(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquared, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int shapeStepSize, const unsigned int shapeTopBand, const unsigned int shapeBottomBand, const ResponseType responseType, const double minimalGradient, const double varianceFactor, const double minimalVariance, const double maximalRatio, const GradientResponseStrategy gradientResponseStrategy, const BandStrategy bandStrategy)
Determines the gradient-based T-shape detector response.
BandStrategy
Definition of individual band strategies.
Definition: TestShapeDetector.h:185
This class implements tests for the Shape detector.
Definition: TestShapeDetector.h:34
static bool testGradientVarianceBasedTShapeDetectorHorizontalResponse(const double testDuration)
Test the horizontal response of the gradient&variance-based T-shape detector.
static bool testGradientBasedTShapeDetector(const double testDuration)
Test the gradient-based T-shape detector.
CV::Detector::ShapeDetector::XShapes XShapes
Definition: TestShapeDetector.h:43
ResponseVisualization
Definition of individual response visualization types.
Definition: TestShapeDetector.h:64
static bool test(const double testDuration)
Tests the shape detector functions.
ResponseType
Definition of indivdual response types.
Definition: TestShapeDetector.h:51
static bool testGradientVarianceBasedTShapeDetectorVerticalResponse(const double testDuration)
Test the vertical response of the gradient&variance-based T-shape detector.
CV::Detector::ShapeDetector::LShapes LShapes
Definition: TestShapeDetector.h:41
static bool compareTshapes(const TShape &left, const TShape &right)
Compares two T-shapes and returns whether the left shape has a higher score.
Definition: TestShapeDetector.h:481
CV::Detector::ShapeDetector::TShapes TShapes
Definition: TestShapeDetector.h:42
static bool testGradientVarianceBasedTShapeDetector(const double testDuration)
Test the gradient&variance-based T-shape detector.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15