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