Ocean
Loading...
Searching...
No Matches
Barcode.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
12namespace Ocean
13{
14
15namespace CV
16{
17
18namespace Detector
19{
20
21namespace Barcodes
22{
23
24/// Forward declaration
25class Barcode;
26
27/// Definition of a vector of barcodes
28typedef std::vector<Barcode> Barcodes;
29
30/**
31 * Definition of barcode types
32 * @ingroup cvdetectorbarcodes
33 */
34enum class BarcodeType : uint32_t
35{
36 /// An invalid barcode type
37 INVALID = 0u,
38 /// A barcode of type EAN-13
39 EAN_13 = 1u << 0u,
40 /// A barcode of type UPC-A
41 UPC_A = 1u << 1u,
42};
43
44/// Definition of a set of barcode types
45typedef std::unordered_set<BarcodeType> BarcodeTypeSet;
46
47/**
48 * Definition of a barcode
49 * @ingroup cvdetectorbarcodes
50 */
52{
53 public:
54
55 /**
56 * Creates an invalid barcode instance
57 */
58 Barcode() = default;
59
60 /**
61 * Creates a barcode object
62 * @param barcodeType The type of the barcode, must not be `BarcodeType::INVALID`
63 * @param data The data that will be stored for this barcode, must not be empty
64 */
65 inline Barcode(const BarcodeType barcodeType, const std::string& data);
66
67 /**
68 * Creates a barcode object
69 * @param barcodeType The type of the barcode, must not be `BarcodeType::INVALID`
70 * @param data The data that will be stored for this barcode, must not be empty
71 */
72 inline Barcode(const BarcodeType barcodeType, std::string&& data);
73
74 /**
75 * Returns whether this is a valid barcode instance
76 * @return True if this is a valid barcode instance, otherwise false
77 */
78 inline bool isValid() const;
79
80 /**
81 * Returns the type of this barcode
82 * @return The type of this barcode
83 */
84 inline BarcodeType barcodeType() const;
85
86 /**
87 * Returns the payload of this barcode
88 * @return The payload
89 */
90 inline const std::string& data() const;
91
92 /**
93 * Translates a barcode type into a human-readable string
94 * @param barcodeType The barcode type that will be converted into a string
95 * @return The translated barcode type
96 */
97 static inline std::string translateBarcodeType(const BarcodeType barcodeType);
98
99 protected:
100
101 /// The type of this barcode
103
104 /// The payload of barcode
105 std::string data_;
106};
107
108inline Barcode::Barcode(const BarcodeType barcodeType, const std::string& data) :
109 barcodeType_(barcodeType),
110 data_(data)
111{
112 ocean_assert(barcodeType_ != BarcodeType::INVALID);
113 ocean_assert(!data_.empty());
114}
115
116inline Barcode::Barcode(const BarcodeType barcodeType, std::string&& data) :
117 barcodeType_(barcodeType),
118 data_(std::move(data))
119{
120 ocean_assert(barcodeType_ != BarcodeType::INVALID);
121 ocean_assert(!data_.empty());
122}
123
124inline bool Barcode::isValid() const
125{
127}
128
130{
131 return barcodeType_;
132}
133
134inline const std::string& Barcode::data() const
135{
136 return data_;
137}
138
139inline std::string Barcode::translateBarcodeType(const BarcodeType barcodeType)
140{
141 switch (barcodeType)
142 {
144 return "INVALID";
145
147 return "EAN-13";
148
150 return "UPC-A";
151 }
152
153 ocean_assert(false && "Never be here!");
154 return "Unknown barcode type";
155}
156
157} // namespace QRCodes
158
159} // namespace Detector
160
161} // namespace CV
162
163} // namespace Ocean
Definition of a barcode.
Definition Barcode.h:52
BarcodeType barcodeType_
The type of this barcode.
Definition Barcode.h:102
const std::string & data() const
Returns the payload of this barcode.
Definition Barcode.h:134
bool isValid() const
Returns whether this is a valid barcode instance.
Definition Barcode.h:124
BarcodeType barcodeType() const
Returns the type of this barcode.
Definition Barcode.h:129
static std::string translateBarcodeType(const BarcodeType barcodeType)
Translates a barcode type into a human-readable string.
Definition Barcode.h:139
Barcode()=default
Creates an invalid barcode instance.
std::string data_
The payload of barcode.
Definition Barcode.h:105
BarcodeType
Definition of barcode types.
Definition Barcode.h:35
std::unordered_set< BarcodeType > BarcodeTypeSet
Definition of a set of barcode types.
Definition Barcode.h:45
std::vector< Barcode > Barcodes
Definition of a vector of barcodes.
Definition Barcode.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15