Ocean
TestMessengerCodeDetector.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_MESSENGER_CODE_DETECTOR_H
9 #define META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_MESSENGER_CODE_DETECTOR_H
10 
12 
14 
16 
19 
20 #ifdef OCEAN_USE_LOCAL_TEST_DATA_COLLECTION
21  #ifndef OCEAN_USE_TEST_DATA_COLLECTION
22  #define OCEAN_USE_TEST_DATA_COLLECTION
23  #endif
24 #endif // OCEAN_USE_LOCAL_TEST_DATA_COLLECTION
25 
26 namespace Ocean
27 {
28 
29 namespace Test
30 {
31 
32 namespace TestCV
33 {
34 
35 namespace TestDetector
36 {
37 
38 /**
39  * This class implements a test for the Messenger Code detector.
40  * @ingroup testcvdetector
41  */
42 class OCEAN_TEST_CV_DETECTOR_EXPORT TestMessengerCodeDetector : protected CV::Detector::MessengerCodeDetector
43 {
44  public:
45 
46  /**
47  * This class implements a test data collection based on local files.
48  */
50  {
51  public:
52 
53  /**
54  * Creates a new test data collection object.
55  * @param imageFilenames The filenames of all local images which will be part of the test collection
56  */
57  explicit FileDataCollection(std::vector<std::string>&& imageFilenames);
58 
59  /**
60  * Returns the test data object associated with a specified index.
61  * @see TestDataCollection::data().
62  */
63  SharedTestData data(const size_t index) override;
64 
65  /**
66  * Returns the number of data object objects this collection holds.
67  * @see TestDataCollection::size().
68  */
69  size_t size() override;
70 
71  protected:
72 
73  /// The filenames of all local images belonging to this test collection.
74  std::vector<std::string> filenames_;
75  };
76 
77  public:
78 
79  /**
80  * Invokes all test for the Messenger Code detector.
81  * @param testDuration Number of seconds for each test, with range (0, infinity)
82  * @param worker The worker object
83  * @return True, if succeeded
84  */
85  static bool test(const double testDuration, Worker& worker);
86 
87  /**
88  * Tests the extraction of code candidates.
89  * @param testDuration Number of seconds for each test, with range (0, infinity)
90  * @return True, if succeeded
91  */
92  static bool testExtractCodeCandidates(const double testDuration);
93 
94  /**
95  * Tests the detection of artificial rendered bullseyes.
96  * @param filterSize The size of the Gaussian blur kernel to be applied, with range [1, infinity), must be odd, 0 to avoid blur
97  * @param testDuration Number of seconds for each test, with range (0, infinity)
98  * @return True, if succeeded
99  */
100  static bool testBullseyeDetectionArtificial(const unsigned int filterSize, const double testDuration);
101 
102  /**
103  * Applies a stress test.
104  * @param testDuration Number of seconds for each test, with range (0, infinity)
105  * @param worker The worker object
106  * @return True, if succeeded
107  */
108  static bool testStressTest(const double testDuration, Worker& worker);
109 
110 #ifdef OCEAN_USE_TEST_DATA_COLLECTION
111 
112  /**
113  * Tests real images in which exactly one bullseye is visible (in the center of the image).
114  * The images needs to be provided via a test data collection with name "messengercodedetector_1bullseye".
115  * @param worker The worker object
116  * @return True, if succeeded
117  */
118  static bool testDetect1Bullseye(Worker& worker);
119 
120  /**
121  * Tests real images in which no Messenger code is visible.
122  * The images needs to be provided via a test data collection with name "messengercodedetector_0code".
123  * @param worker The worker object
124  * @return True, if succeeded
125  */
126  static bool testDetect0Code(Worker& worker);
127 
128  /**
129  * Tests real images in which exactly one Messenger code is visible.
130  * The images needs to be provided via a test data collection with name "messengercodedetector_1code".
131  * @param worker The worker object
132  * @return True, if succeeded
133  */
134  static bool testDetect1Code(Worker& worker);
135 
136 #endif // OCEAN_USE_TEST_DATA_COLLECTION
137 
138  protected:
139 
140  /**
141  * Calculates four corners for one Messenger Code.
142  * The four corners will be rotated randomly.
143  * @param codeCenter The center of the Messenger Code
144  * @param distance The distance between neighboring corners, with range (0, infinity)
145  * @param randomGenerator Random generator object
146  * @return The four corners
147  */
148  static Vectors2 createCodeCorners(const Vector2& codeCenter, const Scalar distance, RandomGenerator& randomGenerator);
149 
150  /**
151  * Paints a bullseye into a given 8 bit grayscale frame.
152  * @param frame The frame in which the bullseye will be painted, must be valid
153  * @param width The width of the given frame in pixel, with range [21, infinity)
154  * @param height The height of the given frame in pixel, with range [21, infinity)
155  * @param location The bullseye's center location within the frame
156  * @param radius The bullseye's radius, with range (3, infinity)
157  * @param foregroundColor The foreground color to be used
158  * @param backgroundColor The background color to be used
159  * @param framePaddingElements The number of padding elements at the end of each image row, in elements, with range [0, infinity)
160  */
161  static void paintBullseye(unsigned char* frame, const unsigned int width, const unsigned int height, const Vector2& location, const Scalar radius, const unsigned char foregroundColor, const unsigned char backgroundColor, const unsigned int framePaddingElements);
162 
163  /**
164  * Paints noise into a given 8 bit grayscale frame.
165  * @param yFrame The frame in which the bullseye will be painted, with pixel format FORMAT_Y8, must be valid
166  * @param location The center location of the noise within the frame
167  * @param foregroundColor The foreground color to be used
168  */
169  static void paintNoise(Frame& yFrame, const Vector2& location, const uint8_t foregroundColor);
170 };
171 
172 #ifdef OCEAN_USE_TEST_DATA_COLLECTION
173 
174 /**
175  * Registers the data collections for the MessengerCodeDetector test.
176  * @return The scoped subscriptions for the registered data collections
177  */
179 
180 #endif // OCEAN_USE_LOCAL_TEST_DATA_COLLECTION
181 
182 }
183 
184 }
185 
186 }
187 
188 }
189 
190 #endif // META_OCEAN_TEST_TESTCV_TESTDETECTOR_TEST_MESSENGER_CODE_DETECTOR_H
This class implements a detector for circular Messenger Codes.
Definition: MessengerCodeDetector.h:39
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements a test data collection based on local files.
Definition: TestMessengerCodeDetector.h:50
size_t size() override
Returns the number of data object objects this collection holds.
std::vector< std::string > filenames_
The filenames of all local images belonging to this test collection.
Definition: TestMessengerCodeDetector.h:74
FileDataCollection(std::vector< std::string > &&imageFilenames)
Creates a new test data collection object.
SharedTestData data(const size_t index) override
Returns the test data object associated with a specified index.
This class implements a test for the Messenger Code detector.
Definition: TestMessengerCodeDetector.h:43
static bool testDetect0Code(Worker &worker)
Tests real images in which no Messenger code is visible.
static bool test(const double testDuration, Worker &worker)
Invokes all test for the Messenger Code detector.
static bool testStressTest(const double testDuration, Worker &worker)
Applies a stress test.
static void paintBullseye(unsigned char *frame, const unsigned int width, const unsigned int height, const Vector2 &location, const Scalar radius, const unsigned char foregroundColor, const unsigned char backgroundColor, const unsigned int framePaddingElements)
Paints a bullseye into a given 8 bit grayscale frame.
static bool testExtractCodeCandidates(const double testDuration)
Tests the extraction of code candidates.
static bool testDetect1Bullseye(Worker &worker)
Tests real images in which exactly one bullseye is visible (in the center of the image).
static void paintNoise(Frame &yFrame, const Vector2 &location, const uint8_t foregroundColor)
Paints noise into a given 8 bit grayscale frame.
static bool testBullseyeDetectionArtificial(const unsigned int filterSize, const double testDuration)
Tests the detection of artificial rendered bullseyes.
static bool testDetect1Code(Worker &worker)
Tests real images in which exactly one Messenger code is visible.
static Vectors2 createCodeCorners(const Vector2 &codeCenter, const Scalar distance, RandomGenerator &randomGenerator)
Calculates four corners for one Messenger Code.
This class is the base class for all TestDataCollection objects.
Definition: TestDataCollection.h:35
std::vector< ScopedSubscription > ScopedSubscriptions
Definition of a vector holding scoped subscription objects.
Definition: TestDataManager.h:43
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
std::shared_ptr< TestData > SharedTestData
Definition of a shared pointer holding a TestData object.
Definition: TestData.h:29
TestDataManager::ScopedSubscriptions TestMessengerCodeDetector_registerTestDataCollections()
Registers the data collections for the MessengerCodeDetector test.
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15