Ocean
LegacyQRCodeDetector2D.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 
15 
16 #include "ocean/base/Frame.h"
17 #include "ocean/base/Memory.h"
18 
19 #include "ocean/cv/Bresenham.h"
20 
22 
23 #include "ocean/math/Box2.h"
25 #include "ocean/math/Vector2.h"
26 
27 #include <array>
28 #include <cstdint>
29 
30 namespace Ocean
31 {
32 
33 namespace CV
34 {
35 
36 namespace Detector
37 {
38 
39 namespace QRCodes
40 {
41 
42 /**
43  * Deprecated: use QRCodeDetector2D instead
44  *
45  * This class implements a detector for QR Codes.
46  * @ingroup cvdetectorqrcodes
47  */
48 class OCEAN_CV_DETECTOR_QRCODES_EXPORT LegacyQRCodeDetector2D : public QRCodeDetector
49 {
50  public:
51 
52  /**
53  * Definition of different detection modes
54  */
55  enum DetectionMode : uint32_t
56  {
57  /// Uses the standard array of checks to detect QR codes
58  DM_STANDARD = 1u << 0u,
59  /// Will add a small border around each image, e.g., if the QR code occupies the entire image leaving too little space to the border
60  DM_EXTRA_BORDER = 1u << 1u,
61  /// Will enable blurring of the input image as an additional measure to detect QR codes
62  DM_BLUR = 2u << 1u,
63  /// Uses a minimum of detection tests for fast detections
64  DM_BEST_PERFORMANCE = DM_STANDARD,
65  /// Enables all additional checks for best detection results
66  DM_BEST_DETECTION = DM_STANDARD | DM_EXTRA_BORDER | DM_BLUR
67  };
68 
69  /**
70  * Definition of an observation of QR code in 2D
71  */
73  {
74  public:
75 
76  /**
77  * Creates an invalid observation
78  */
79  Observation() = default;
80 
81  /**
82  * Creates an valid observation
83  * @param frame_H_code The homography that maps coordinates in the QR code grid to image coordinates, i.e., `frameLocation = frame_H_code_ * (codeX + 0.5, codeY + 0.5)^T`
84  * @param finderPatterns The three finder patterns of the QR Codes, elements must be in the order: top-left, bottom-left, top-right
85  */
86  inline explicit Observation(const SquareMatrix3& frame_H_code, FinderPatternTriplet&& finderPatterns);
87 
88  /**
89  * Returns if the observation is valid
90  * @return True if the observation is valid, otherwise false
91  */
92  inline bool isValid() const;
93 
94  /**
95  * Returns the homography that maps coordinates in the QR code grid to image coordinates
96  * @return The homography
97  */
98  inline const SquareMatrix3& frame_H_code() const;
99 
100  /**
101  * Returns a pointer to the finder patterns
102  * @return The finder patterns
103  */
104  inline const FinderPatternTriplet& finderPatterns() const;
105 
106  protected:
107 
108  /// The homography that maps coordinates in the QR code grid to image coordinates, i.e., `frameLocation = frame_H_code_ * (codeX + 0.5, codeY + 0.5)^T`
109  SquareMatrix3 frame_H_code_ = SquareMatrix3(false);
110 
111  /// The finder patterns of the QR code, order: top-left, bottom-left, top-right
113  };
114 
115  /// Definition of a vector of observations
116  typedef std::vector<Observation> Observations;
117 
118  public:
119 
120  /**
121  * Detects QR codes in a given 8 bit grayscale image.
122  * @param frame The frame in which the QR codes will be detected, must be an 8 bit grayscale image and must be valid
123  * @param worker Optional worker to distribute the computation
124  * @param detectionMode The detection mode that should be used
125  * @param observations If specified, will return the observations of the detected QR codes; the order matches the elements of the return value
126  * @return An array of detected QR codes
127  */
128  static inline QRCodes detectQRCodes(const Frame& frame, Worker* worker = nullptr, const DetectionMode detectionMode = DM_STANDARD, Observations* observations = nullptr);
129 
130  /**
131  * Detects QR codes in a given 8 bit grayscale image.
132  * @param yFrame The 8 bit grayscale frame in which the QR codes will be detected, must be valid
133  * @param width The width of the given grayscale frame in pixel, with range [29, infinity)
134  * @param height The height of the given grayscale frame in pixel, with range [29, infinity)
135  * @param paddingElements Optional number of padding elements at the end of each image row, in elements, with range [0, infinity)
136  * @param worker Optional worker to distribute the computation
137  * @param detectionMode The detection mode that should be used
138  * @param observations If specified, will return the observations of the detected QR codes; the order matches the elements of the return value
139  * @return An array of detected QR codes
140  */
141  static QRCodes detectQRCodes(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int paddingElements = 0u, Worker* worker = nullptr, const DetectionMode detectionMode = DM_STANDARD, Observations* observations = nullptr);
142 
143  protected:
144 
145  /**
146  * Determines the three outer corners of a finder pattern triplet in a QR code
147  * Given a (valid) triplet of finder patterns, their corners can be used to determine three (out of four) corners of the QR code, i.e., the top-left corner `(0, 0)`, the bottom-left corner `(0, qrcodesize)`, and the top-right corner `(qrcodesize, 0)`
148  * @note Make sure that the triplet is valid, otherwise the result will be undefined.
149  * @param topLeft The finder pattern in the top-left corner
150  * @param bottomLeft The finder pattern in the bottom-left corner
151  * @param topRight The finder pattern in the top-right corner
152  * @param cornerIndexTopLeft The resulting index of the corner of the top-left finder pattern that is also the top-left corner of the entire QR code symbol, will be in the range: [0, 4) (cf. `QRCode::corner()`)
153  * @param cornerIndexBottomLeft The resulting index of the corner of the bottom-left finder pattern that is also the bottom-left corner of the entire QR code symbol, will be in the range: [0, 4) (cf. `QRCode::corner()`)
154  * @param cornerIndexTopRight The resulting index of the corner of the top-right finder pattern that is also the top-right corner of the entire QR code symbol, will be in the range: [0, 4) (cf. `QRCode::corner()`)
155  * @return True if the three corners were successfully determined, otherwise false
156  */
157  static bool determineOuterMostCorners(const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, unsigned int& cornerIndexTopLeft, unsigned int& cornerIndexBottomLeft, unsigned int& cornerIndexTopRight);
158 
159  /**
160  * Extracts the version of a QR code from an image given its known location
161  * @param yFrame Pointer to the input grayscale image, must be valid
162  * @param width The width of the input grayscale image, range: [1, infinity)
163  * @param height The height of the input grayscale image, range:[1, infinity)
164  * @param yFramePaddingElements The number of padding elements of the input grayscale image, range: [0, infinity)
165  * @param topLeft The finder pattern in the top-left corner of the QR code, must be valid
166  * @param bottomLeft The finder pattern in the bottom-left corner of the QR code, must be valid
167  * @param topRight The finder pattern in the top-right corner of the QR code, must be valid
168  * @param estimatedVersion The version number that was estimated from the module size of the finder patterns, range: [7u, 40u]
169  * @param homography A transformation which is used to extract the modules (bits) of the version information, maps QR code location `q = (u, v)` to image coordinates `p = (x, y)`: `p = affineTransform * (u + 0.5, v + 0.5)`
170  * @param version Will hold the resulting version number that is extracted from the image of QR code
171  * @return True if the version was successfully extracted, otherwise false
172  * @sa computeInitialHomography()
173  */
174  static bool determineSymbolVersionFromImage(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, const unsigned int estimatedVersion, const SquareMatrix3& homography, unsigned int& version);
175 
176  /**
177  * Detects the timer pattern between (1) the top-left and top-right or (2) the top-left and bottom-left finder patterns
178  * @param yFrame Pointer to the input grayscale image, must be valid
179  * @param width The width of the input grayscale image, range: [1, infinity)
180  * @param height The height of the input grayscale image, range:[1, infinity)
181  * @param yFramePaddingElements The number of padding elements of the input grayscale image, range: [0, infinity)
182  * @param version The version number that was determined for this QR code, range: [1u, 40u]
183  * @param homography Homography transformation that describes the location of the QR code for which the detection of the timing pattern will be run, must be valid
184  * @param topLeft The finder pattern in the top-left corner of the QR code, must be valid
185  * @param bottomLeft The finder pattern in the bottom-left corner of the QR code, must be valid
186  * @param topRight The finder pattern in the top-right corner of the QR code, must be valid
187  * @return True if 1) at least one timer pattern has been detected 100%, or 2) both timer patterns have been detected 80% each, otherwise false
188  */
189  static bool detectTimerPatterns(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const unsigned int version, const SquareMatrix3& homography, const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight);
190 
191  /**
192  * Extracts the format information of a QR code from an image given its known location
193  * @param yFrame Pointer to the input grayscale image, must be valid
194  * @param width The width of the input grayscale image, range: [1, infinity)
195  * @param height The height of the input grayscale image, range:[1, infinity)
196  * @param yFramePaddingElements The number of padding elements of the input grayscale image, range: [0, infinity)
197  * @param topLeft The finder pattern in the top-left corner of the QR code, must be valid
198  * @param bottomLeft The finder pattern in the bottom-left corner of the QR code, must be valid
199  * @param topRight The finder pattern in the top-right corner of the QR code, must be valid
200  * @param version The version number that was determined for this QR code, range: [1u, 40u]
201  * @param homography A transformation which is used to extract the modules (bits) of the version information, maps QR code location `q = (u, v)` to image coordinates `p = (x, y)`: `p = affineTransform * (u + 0.5, v + 0.5)`
202  * @param errorCorrectionCapacity The resulting error correction capacity that the QR code in the image was created with
203  * @param maskingPattern The resulting masking pattern that was used to XOR the modules of the QR code in the image at its creation time
204  * @return True if the format information was successfully read from image and could be decoded
205  */
206  static bool determineSymbolFormat(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, const unsigned int version, const SquareMatrix3& homography, QRCode::ErrorCorrectionCapacity& errorCorrectionCapacity, QRCodeEncoder::MaskingPattern& maskingPattern);
207 
208  /**
209  * Computes an initial transformation to map QR code coordinates to image locations
210  * @note Make sure that the triplet is valid, otherwise the result will be undefined.
211  * @param topLeft The finder pattern in the top-left corner
212  * @param bottomLeft The finder pattern in the bottom-left corner
213  * @param topRight The finder pattern in the top-right corner
214  * @param version The version of the QR code defined by the above triplet of finder patterns, range: [1, 40]
215  * @param cornerIndexTopLeft The index of the corner of the top-left finder pattern that is also the top-left corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`), set this to a value outside the range if this index isn't known
216  * @param cornerIndexBottomLeft The index of the corner of the bottom-left finder pattern that is also the bottom-left corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`), set this to a value outside the range if this index isn't known
217  * @param cornerIndexTopRight The index of the corner of the top-right finder pattern that is also the top-right corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`), set this to a value outside the range if this index isn't known
218  * @param homography The resulting homography that is computed from the triplet of finder patterns. In case not all corners of the finder patterns are known, this transformation will be an affine transformation, not a full homography. The transformation maps QR code coordinates `(u, v)` to image locations, `p = (x, y)`: `p = homography * (u + 0.5, v + 0.5)`
219  * @return True if the computation of the homography was successful, otherwise false
220  */
221  static inline bool computeInitialHomography(const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, const unsigned int& version, const unsigned int cornerIndexTopLeft, const unsigned int cornerIndexBottomLeft, const unsigned int cornerIndexTopRight, SquareMatrix3& homography);
222 
223  /**
224  * Computes the homography for a valid triplet finder patterns and known version of the underlying QR code
225  * Locates the alignment patterns of the QR code and uses them in order to refine the estimate of the initial homography
226  * @param yFrame Pointer to a grayscale image of size `width x height` pixels, must be valid
227  * @param width The width of the input frame, range: [1, infinity)
228  * @param height The height of the input frame, range: [1, infinity)
229  * @param yFramePaddingElements Number of padding elements of this frame, range: [0, infinity)
230  * @param topLeft The finder pattern in the top-left corner of the QR code, must be valid
231  * @param bottomLeft The finder pattern in bottom-left corner of the QR code, must be valid
232  * @param topRight The finder pattern in the top-right corner of the QR code, must be valid
233  * @param cornerIndexTopLeft The index of the corner of the top-left finder pattern that is also the top-left corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`)
234  * @param cornerIndexBottomLeft The index of the corner of the bottom-left finder pattern that is also the bottom-left corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`)
235  * @param cornerIndexTopRight The index of the corner of the top-right finder pattern that is also the top-right corner of the entire QR code symbol, range: [0, 4) (cf. `QRCode::corner()`)
236  * @param version The version number of the QR code, range: [1, 40]
237  * @param initialHomography An initial transformation to map QR code coordinates to image locations that will be refined
238  * @param homography The resulting transformation mapping coordinates in the QR code, `q = (u, v)`, into image coordinate, `p = (x, y)`: `p = homography * q`
239  * @return True if the homography was computed successfully, otherwise false
240  */
241  static bool computeRefinedHomography(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, const unsigned int cornerIndexTopLeft, const unsigned int cornerIndexBottomLeft, const unsigned int cornerIndexTopRight, unsigned int& version, const SquareMatrix3& initialHomography, SquareMatrix3& homography);
242 
243  /**
244  * Read the modules of a QR code with known location (homography) from an image
245  * @param yFrame Pointer to a grayscale image of size `width x height` pixels, must be valid
246  * @param width The width of the input frame, range: [1, infinity)
247  * @param height The height of the input frame, range: [1, infinity)
248  * @param yFramePaddingElements Number of padding elements of this frame, range: [0, infinity)
249  * @param grayThreshold The threshold that was used during the detection of this QR code, range: [0, 255]
250  * @param version The version number of the QR code, range: [1, 40]
251  * @param homography The transformation mapping coordinates in the QR code, `q = (u, v)`, into image coordinate, `p = (x, y)`: `p = homography * q`
252  * @param modules The resulting modules (bits) of the QR code that have been identified in the image, `yFrame`. Memory will be allocated inside this function, if necessary
253  * @return True, if the modules were read successfully, otherwise false
254  */
255  static bool extractModules(const uint8_t* const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const unsigned int grayThreshold, const unsigned int version, const SquareMatrix3& homography, std::vector<uint8_t>& modules);
256 };
257 
259  frame_H_code_(frame_H_code),
260  finderPatterns_(std::move(finderPatterns))
261 {
262  // Nothing else to do.
263 }
264 
266 {
267  return frame_H_code_.isHomography();
268 }
269 
271 {
272  return frame_H_code_;
273 }
274 
276 {
277  return finderPatterns_;
278 }
279 
280 inline QRCodes LegacyQRCodeDetector2D::detectQRCodes(const Frame& frame, Worker* worker, const DetectionMode detectionMode, Observations* observations)
281 {
283  {
284  ocean_assert(false && "Frame must be valid and an 8 bit grayscale image and the pixel origin must be the upper left corner");
285  QRCodes();
286  }
287 
288  return detectQRCodes(frame.constdata<uint8_t>(), frame.width(), frame.height(), frame.paddingElements(), worker, detectionMode, observations);
289 }
290 
291 inline bool LegacyQRCodeDetector2D::computeInitialHomography(const FinderPattern& topLeft, const FinderPattern& bottomLeft, const FinderPattern& topRight, const unsigned int& version, const unsigned int cornerIndexTopLeft, const unsigned int cornerIndexBottomLeft, const unsigned int cornerIndexTopRight, SquareMatrix3& homography)
292 {
293  ocean_assert(version >= 1u && version <= 40u);
294 
295  const unsigned int modules = QRCode::modulesPerSide(std::min(40u, version));
296 
297  if (topLeft.cornersKnown() && bottomLeft.cornersKnown() && topRight.cornersKnown() && cornerIndexTopLeft < 4u && cornerIndexBottomLeft < 4u && cornerIndexTopRight < 4u)
298  {
299  // Compute a homography from the corners of the finder patterns (3 x 4 points)
300  //
301  // Define the initial set of point correspondences. Here, use the four corners of the three finder patterns
302  // (top-left, bottom-left, and top-right):
303  //
304  // TL TR
305  // *0--3 9--8*
306  // | | | |
307  // 1--2 10--11
308  //
309  // 7--6
310  // | |
311  // *4--5
312  // BL
313  //
314  // The numbers indicate the index in the list of points below. The asterik (*) denotes the outer-most corners
315  // that were determined above. Because the corners of the finder patterns are in counter-clockwise order, they
316  // can easily be enumerated using `i & 0b0011u` as cheaper equivalent to `i % 4`.
317 
318  const Vector2 imagePoints[12] =
319  {
320  // Corners of the top-left finder pattern
321  topLeft.corners()[(cornerIndexTopLeft + 0u) & 0b0011u], // (cornerIndexTopLeft + x) & 0b0011u == (cornerIndexTopLeft + x) % 4
322  topLeft.corners()[(cornerIndexTopLeft + 1u) & 0b0011u],
323  topLeft.corners()[(cornerIndexTopLeft + 2u) & 0b0011u],
324  topLeft.corners()[(cornerIndexTopLeft + 3u) & 0b0011u],
325 
326  // Corners of the bottom-left finder pattern
327  bottomLeft.corners()[(cornerIndexBottomLeft + 0u) & 0b0011u],
328  bottomLeft.corners()[(cornerIndexBottomLeft + 1u) & 0b0011u],
329  bottomLeft.corners()[(cornerIndexBottomLeft + 2u) & 0b0011u],
330  bottomLeft.corners()[(cornerIndexBottomLeft + 3u) & 0b0011u],
331 
332  // Corners of the top-right finder pattern
333  topRight.corners()[(cornerIndexTopRight + 0u) & 0b0011u],
334  topRight.corners()[(cornerIndexTopRight + 1u) & 0b0011u],
335  topRight.corners()[(cornerIndexTopRight + 2u) & 0b0011u],
336  topRight.corners()[(cornerIndexTopRight + 3u) & 0b0011u],
337  };
338 
339  const Vector2 qrcodePoints[12] =
340  {
341  // Corners of the top-left finder pattern
342  Vector2(Scalar(0), Scalar(0)),
343  Vector2(Scalar(0), Scalar(7)),
344  Vector2(Scalar(7), Scalar(7)),
345  Vector2(Scalar(7), Scalar(0)),
346 
347  // Corners of the bottom-left finder pattern
348  Vector2(Scalar(0), Scalar(modules)),
349  Vector2(Scalar(7), Scalar(modules)),
350  Vector2(Scalar(7), Scalar(modules - 7u)),
351  Vector2(Scalar(0), Scalar(modules - 7u)),
352 
353  // Corners of the top-right finder pattern
354  Vector2(Scalar(modules), Scalar(0)),
355  Vector2(Scalar(modules - 7u), Scalar(0)),
356  Vector2(Scalar(modules - 7u), Scalar(7)),
357  Vector2(Scalar(modules), Scalar(7)),
358  };
359 
360  if (Geometry::Homography::homographyMatrixLinearWithOptimizations(qrcodePoints, imagePoints, 12u, homography))
361  {
362  return true;
363  }
364  }
365 
366  // If the above didn't work, compute an affine transformation from the centers of the finder patterns (3 x 1 points, affine transformations are a special case of homographies)
367  const Vector2 imagePoints[3] =
368  {
369  topLeft.position(),
370  bottomLeft.position(),
371  topRight.position()
372  };
373 
374  const Vector2 rectifiedPoints[3] =
375  {
376  Vector2(Scalar(3.5), Scalar(3.5)),
377  Vector2(Scalar(3.5), Scalar(modules) - Scalar(3.5)),
378  Vector2(Scalar(modules) - Scalar(3.5), Scalar(3.5))
379  };
380 
381  return Geometry::Homography::affineMatrix(rectifiedPoints, imagePoints, 3u, homography);
382 }
383 
384 } // namespace QRCodes
385 
386 } // namespace Detector
387 
388 } // namespace CV
389 
390 } // namespace Ocean
Definition of a class for finder patterns of QR codes (squares in the top-left, top-right and bottom-...
Definition: FinderPatternDetector.h:58
const Vector2 * corners() const
Returns a pointer to the four corners of this finder pattern.
Definition: FinderPatternDetector.h:530
bool cornersKnown() const
Returns true if the four corners of this finder pattern are known, otherwise false.
Definition: FinderPatternDetector.h:525
const Vector2 & position() const
Returns the (center) position of the finder pattern.
Definition: FinderPatternDetector.h:495
Definition of an observation of QR code in 2D.
Definition: LegacyQRCodeDetector2D.h:73
Observation()=default
Creates an invalid observation.
bool isValid() const
Returns if the observation is valid.
Definition: LegacyQRCodeDetector2D.h:265
FinderPatternTriplet finderPatterns_
The finder patterns of the QR code, order: top-left, bottom-left, top-right.
Definition: LegacyQRCodeDetector2D.h:112
const FinderPatternTriplet & finderPatterns() const
Returns a pointer to the finder patterns.
Definition: LegacyQRCodeDetector2D.h:275
const SquareMatrix3 & frame_H_code() const
Returns the homography that maps coordinates in the QR code grid to image coordinates.
Definition: LegacyQRCodeDetector2D.h:270
Deprecated: use QRCodeDetector2D instead.
Definition: LegacyQRCodeDetector2D.h:49
static QRCodes detectQRCodes(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int paddingElements=0u, Worker *worker=nullptr, const DetectionMode detectionMode=DM_STANDARD, Observations *observations=nullptr)
Detects QR codes in a given 8 bit grayscale image.
static bool determineOuterMostCorners(const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight, unsigned int &cornerIndexTopLeft, unsigned int &cornerIndexBottomLeft, unsigned int &cornerIndexTopRight)
Determines the three outer corners of a finder pattern triplet in a QR code Given a (valid) triplet o...
static bool detectTimerPatterns(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const unsigned int version, const SquareMatrix3 &homography, const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight)
Detects the timer pattern between (1) the top-left and top-right or (2) the top-left and bottom-left ...
static bool determineSymbolFormat(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight, const unsigned int version, const SquareMatrix3 &homography, QRCode::ErrorCorrectionCapacity &errorCorrectionCapacity, QRCodeEncoder::MaskingPattern &maskingPattern)
Extracts the format information of a QR code from an image given its known location.
static bool extractModules(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const unsigned int grayThreshold, const unsigned int version, const SquareMatrix3 &homography, std::vector< uint8_t > &modules)
Read the modules of a QR code with known location (homography) from an image.
static QRCodes detectQRCodes(const Frame &frame, Worker *worker=nullptr, const DetectionMode detectionMode=DM_STANDARD, Observations *observations=nullptr)
Detects QR codes in a given 8 bit grayscale image.
Definition: LegacyQRCodeDetector2D.h:280
static bool computeInitialHomography(const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight, const unsigned int &version, const unsigned int cornerIndexTopLeft, const unsigned int cornerIndexBottomLeft, const unsigned int cornerIndexTopRight, SquareMatrix3 &homography)
Computes an initial transformation to map QR code coordinates to image locations.
Definition: LegacyQRCodeDetector2D.h:291
DetectionMode
Definition of different detection modes.
Definition: LegacyQRCodeDetector2D.h:56
std::vector< Observation > Observations
Definition of a vector of observations.
Definition: LegacyQRCodeDetector2D.h:116
static bool determineSymbolVersionFromImage(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight, const unsigned int estimatedVersion, const SquareMatrix3 &homography, unsigned int &version)
Extracts the version of a QR code from an image given its known location.
static bool computeRefinedHomography(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const FinderPattern &topLeft, const FinderPattern &bottomLeft, const FinderPattern &topRight, const unsigned int cornerIndexTopLeft, const unsigned int cornerIndexBottomLeft, const unsigned int cornerIndexTopRight, unsigned int &version, const SquareMatrix3 &initialHomography, SquareMatrix3 &homography)
Computes the homography for a valid triplet finder patterns and known version of the underlying QR co...
ErrorCorrectionCapacity
Enumeration of the levels of error correction The value of the enums correspond to the standard-defin...
Definition: QRCodeBase.h:53
This class implements common functionality of QR code detectors but is not a stand-alone detector.
Definition: QRCodeDetector.h:33
MaskingPattern
Enum for the mask patterns used to shuffle modules of a QR code.
Definition: QRCodeEncoder.h:45
unsigned int modulesPerSide() const override
Returns the number of modules per side of the QR code.
Definition: QRCode.h:129
This class implements Ocean's image class.
Definition: Frame.h:1760
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition: Frame.h:4136
bool isValid() const
Returns whether this frame is valid.
Definition: Frame.h:4416
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition: Frame.h:4010
@ FORMAT_Y8
Pixel format for grayscale images with byte order Y and 8 bits per pixel.
Definition: Frame.h:594
unsigned int width() const
Returns the width of the frame format in pixel.
Definition: Frame.h:3111
PixelOrigin pixelOrigin() const
Returns the pixel origin of the frame.
Definition: Frame.h:3156
static bool arePixelFormatsCompatible(const PixelFormat pixelFormatA, const PixelFormat pixelFormatB)
Returns whether two given pixel formats are compatible.
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition: Frame.h:3121
@ ORIGIN_UPPER_LEFT
The first pixel lies in the upper left corner, the last pixel in the lower right corner.
Definition: Frame.h:1018
unsigned int height() const
Returns the height of the frame in pixel.
Definition: Frame.h:3116
static bool homographyMatrixLinearWithOptimizations(const Vector2 *leftPoints, const Vector2 *rightPoints, const size_t correspondences, SquareMatrix3 &right_H_left)
Calculates the homography (8DOF - translation, rotation, scale, aspect ratio, shear,...
Definition: Homography.h:452
static bool affineMatrix(const ImagePoint *leftPoints, const ImagePoint *rightPoints, const size_t correspondences, SquareMatrix3 &right_A_left)
Calculates the affine transformation (6DOF - translation, rotation, scale, aspect ratio,...
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::array< FinderPattern, 3 > FinderPatternTriplet
Definition of a 3-tuple of finder patterns.
Definition: FinderPatternDetector.h:198
SquareMatrixT3< Scalar > SquareMatrix3
Definition of the SquareMatrix3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with ...
Definition: SquareMatrix3.h:35
float Scalar
Definition of a scalar type.
Definition: Math.h:128
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition: Vector2.h:21
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