Ocean
test/testcv/testdetector/testqrcodes/Utilities.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 #pragma once
9 
11 
13 
15 
16 namespace Ocean
17 {
18 
19 namespace Test
20 {
21 
22 namespace TestCV
23 {
24 
25 namespace TestDetector
26 {
27 
28 namespace TestQRCodes
29 {
30 
31 /**
32  * This class implements utility functions for the QR code tests
33  * @ingroup testcvdetectorqrcodes
34  */
35 class OCEAN_TEST_CV_DETECTOR_QRCODES_EXPORT Utilities
36 {
37  public:
38 
39  /**
40  * Paint randomized noise into a grayscale image
41  * @param yFrame Pointer to the data of a grayscale image. Must be valid.
42  * @param width The width of the frame pointed to by `yFrame`, range: [29, infinity)
43  * @param height The height of the frame pointer to by `yFrame`, range: [29, infinity)
44  * @param paddingElements The number of padding elements of the input frame `yFrame`, range: [0, infinity)
45  * @param location The location of the center of the noise that will be drawn.
46  * @param randomGenerator Random generator that is used to generate random noise
47  * @param foregroundColor Color that is used for the finder pattern, range: [0, 255]
48  * @param extraBorder An optional distance to the image border that all noise samples must be away from in order to be drawn
49  */
50  static void drawNoisePattern(uint8_t* yFrame, const unsigned int width, const unsigned int height, const unsigned int paddingElements, const Vector2& location, RandomGenerator& randomGenerator, const uint8_t foregroundColor, const Scalar extraBorder = Scalar(14));
51 
52  /**
53  * Generates a random string
54  * @param randomGenerator The random generator that will be used to generate the random string
55  * @param minSize The minimum size of the random string, range: [1, infinity)
56  * @param maxSize The maximum size of the random string, range: [minSize, infinity)
57  * @return The generated random string
58  */
59  static std::string generateRandomString(RandomGenerator& randomGenerator, const unsigned int minSize = 1u, const unsigned int maxSize = 15u);
60 
61  /**
62  * Generates random string consisting of decimal digit characters ('0' to '9' only)
63  * @param randomGenerator The random generator that will be used to generate the random data
64  * @param size The size of string that will be generated in number of characters, range: [1, infinity)
65  * @return The generated random numeric string
66  */
67  static std::string generateRandomNumericString(RandomGenerator& randomGenerator, const unsigned int size);
68 
69  /**
70  * Generates random string consisting of characters in alphanumeric character set defined by the QR code standard
71  * @param randomGenerator The random generator that will be used to generate the random data
72  * @param size The size of string that will be generated in number of characters, range: [1, infinity)
73  * @return The generated random alphanumeric string
74  */
75  static std::string generateRandomAlphanumericString(RandomGenerator& randomGenerator, const unsigned int size);
76 
77  /**
78  * Generates a random data that consists of bytes (value range: 0-255)
79  * @param randomGenerator The random generator that will be used to generate the random data
80  * @param length The length of the data that will be generated in bytes, range: [1, infinity)
81  * @param data The memory where the generated data will be stored. Will be initialized internally, if necessary.
82  * @return True if the data was successfully generated, otherwise false
83  */
84  static bool generateRandomByteData(RandomGenerator& randomGenerator, const unsigned int length, std::vector<uint8_t>& data);
85 
86  /**
87  * Generates random data that consists of values that are decimal digits (between 0 and 9, inclusive)
88  * @param randomGenerator The random generator that will be used to generate the random data
89  * @param sizeInBytes The of the data that will be generated in bytes, range: [1, infinity)
90  * @param data The memory where the generated data will be stored. Will be initialized internally, if necessary.
91  * @return True if the data was successfully generated, otherwise false
92  */
93  static bool generateRandomDecimalDigitSequenceData(RandomGenerator& randomGenerator, const unsigned int sizeInBytes, std::vector<uint8_t>& data);
94 
95  /**
96  * Generates a list of unique and random QR codes
97  * @param randomGenerator The random generator that will be used to generate the QR codes
98  * @param numberCodes The number of QR codes that will be generated, range: [1, infinity)
99  * @param codes The resulting list of QR codes
100  * @return True if the requested number of QR codes were successfully generated, otherwise false
101  */
102  static bool generateUniqueRandomQRCodes(RandomGenerator& randomGenerator, const unsigned int numberCodes, CV::Detector::QRCodes::QRCodes& codes);
103 
104  /**
105  * Returns the numeric charset used for encoding numeric data
106  * @return The numeric charset
107  */
108  static const std::string& getNumericCharset();
109 
110  /**
111  * Returns human readable string representation of QRCode state suitable for logging
112  * @param ignoreModules If True, module data is ignored; otherwise, modules data is excluded from resulting string
113  * @return String representation of QRCode
114  */
115  static std::string translateQRCodeToString(const CV::Detector::QRCodes::QRCodeBase& qrcode, const bool ignoreModules = false);
116 };
117 
118 } // namespace TestQRCodes
119 
120 } // namespace TestDetector
121 
122 } // namespace TestCV
123 
124 } // namespace Test
125 
126 } // namespace Test
Base class for QR code implementations.
Definition: QRCodeBase.h:32
This class implements a generator for random numbers.
Definition: RandomGenerator.h:42
This class implements utility functions for the QR code tests.
Definition: test/testcv/testdetector/testqrcodes/Utilities.h:36
static bool generateRandomByteData(RandomGenerator &randomGenerator, const unsigned int length, std::vector< uint8_t > &data)
Generates a random data that consists of bytes (value range: 0-255)
static std::string generateRandomAlphanumericString(RandomGenerator &randomGenerator, const unsigned int size)
Generates random string consisting of characters in alphanumeric character set defined by the QR code...
static bool generateUniqueRandomQRCodes(RandomGenerator &randomGenerator, const unsigned int numberCodes, CV::Detector::QRCodes::QRCodes &codes)
Generates a list of unique and random QR codes.
static std::string generateRandomNumericString(RandomGenerator &randomGenerator, const unsigned int size)
Generates random string consisting of decimal digit characters ('0' to '9' only)
static std::string translateQRCodeToString(const CV::Detector::QRCodes::QRCodeBase &qrcode, const bool ignoreModules=false)
Returns human readable string representation of QRCode state suitable for logging.
static std::string generateRandomString(RandomGenerator &randomGenerator, const unsigned int minSize=1u, const unsigned int maxSize=15u)
Generates a random string.
static void drawNoisePattern(uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int paddingElements, const Vector2 &location, RandomGenerator &randomGenerator, const uint8_t foregroundColor, const Scalar extraBorder=Scalar(14))
Paint randomized noise into a grayscale image.
static bool generateRandomDecimalDigitSequenceData(RandomGenerator &randomGenerator, const unsigned int sizeInBytes, std::vector< uint8_t > &data)
Generates random data that consists of values that are decimal digits (between 0 and 9,...
static const std::string & getNumericCharset()
Returns the numeric charset used for encoding numeric data.
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< QRCode > QRCodes
Definition of a vector of QR codes.
Definition: QRCode.h:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15