Ocean
MicroQRCodeDecoder.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 
14 namespace Ocean
15 {
16 
17 namespace CV
18 {
19 
20 namespace Detector
21 {
22 
23 namespace QRCodes
24 {
25 
26 /**
27  * Definition of a QR code decoder
28  * @ingroup cvdetectorqrcodes
29  */
30 class OCEAN_CV_DETECTOR_QRCODES_EXPORT MicroQRCodeDecoder
31 {
32  public:
33 
34  /*
35  * Definition of a bit stream
36  */
37  class BitStream
38  {
39  public:
40 
41  /**
42  * Constructor for bit streams
43  * @param buffer The buffer holding the bit stream, must be valid
44  * @param numberOfBits The number of bits in the bit stream, range: [0, 8 * buffer.size()]
45  */
46  BitStream(std::vector<uint8_t>&& buffer, const unsigned int numberOfBits);
47 
48  /**
49  * Returns the number of bits remaining in the bit stream
50  */
51  inline unsigned int bitsRemaining();
52 
53  /**
54  * Consumes a number of bits from the bit stream
55  * @param numberOfBits The number of bits to consume, range: [0, max(32, bitsRemaining())]
56  * @return The consumed bits
57  */
58  uint32_t consumeBits(const unsigned int numberOfBits);
59 
60  /**
61  * Peeks at a number of bits from the bit stream, checking if any are non-zero
62  * @param numberOfBits The number of bits to peek, range: [0, bitsRemaining()]
63  * @return True if any of the bits are non-zero, otherwise false
64  */
65  bool peekNonzeroBits(const unsigned int numberOfBits) const;
66 
67  protected:
68 
69  /**
70  * Consumes a single bit from the bit stream
71  * @return True if the bit is non-zero, otherwise false
72  */
73  bool consumeBit();
74 
75  /// The buffer holding the bit stream
76  std::vector<uint8_t> buffer_;
77 
78  /// The portion of the current byte that have already been consumed
79  unsigned int bitsConsumed_;
80 
81  /// The number of bytes that have already been consumed
82  unsigned int bytesConsumed_;
83 
84  /// The number of bits remaining in the bit stream
85  unsigned int bitsRemaining_;
86  };
87 
88  /**
89  * Decodes the modules of a Micro QR code
90  * @param modules The modules of a Micro QR code, e.g., as sampled after a detection, must be valid
91  * @param code The resulting QR code instance that will hold the decoded data
92  * @return True if the modules are successfully decoded, otherwise false
93  */
94  static bool decodeMicroQRCode(const std::vector<uint8_t>& modules, MicroQRCode& code);
95 };
96 
98 {
99  return bitsRemaining_;
100 }
101 
102 } // namespace QRCodes
103 
104 } // namespace Detector
105 
106 } // namespace CV
107 
108 } // namespace Ocean
unsigned int bitsRemaining_
The number of bits remaining in the bit stream.
Definition: MicroQRCodeDecoder.h:85
unsigned int bytesConsumed_
The number of bytes that have already been consumed.
Definition: MicroQRCodeDecoder.h:82
uint32_t consumeBits(const unsigned int numberOfBits)
Consumes a number of bits from the bit stream.
BitStream(std::vector< uint8_t > &&buffer, const unsigned int numberOfBits)
Constructor for bit streams.
unsigned int bitsRemaining()
Returns the number of bits remaining in the bit stream.
Definition: MicroQRCodeDecoder.h:97
unsigned int bitsConsumed_
The portion of the current byte that have already been consumed.
Definition: MicroQRCodeDecoder.h:79
bool consumeBit()
Consumes a single bit from the bit stream.
bool peekNonzeroBits(const unsigned int numberOfBits) const
Peeks at a number of bits from the bit stream, checking if any are non-zero.
std::vector< uint8_t > buffer_
The buffer holding the bit stream.
Definition: MicroQRCodeDecoder.h:76
Definition of a QR code decoder.
Definition: MicroQRCodeDecoder.h:31
static bool decodeMicroQRCode(const std::vector< uint8_t > &modules, MicroQRCode &code)
Decodes the modules of a Micro QR code.
Definition of a Micro QR code.
Definition: MicroQRCode.h:35
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