209 static constexpr
int deltaThreshold = 30;
227 inline int history1();
233 inline int history2();
239 inline int history3();
245 inline int history4();
251 inline int history5();
258 inline void push(
const int newDelta);
268 int deltas_[5] = { 0, 0, 0, 0, 0 };
283 static FinderPatterns detectFinderPatterns(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int minimumDistance = 10u,
const unsigned int paddingElements = 0u,
Worker* worker =
nullptr);
308 static void detectFinderPatternsSubset(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
FinderPatterns* finderPatterns,
Lock* multiThreadLock,
const unsigned int paddingElements,
const unsigned int firstRow,
const unsigned int numberRows);
319 static void detectFinderPatternInRow(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int y,
FinderPatterns& finderPatterns,
const unsigned int paddingElements);
368 static bool checkFinderPatternInNeighborhood(
const uint8_t*
const yFrame,
const unsigned width,
const unsigned height,
const unsigned int paddingElements,
const unsigned int xCenter,
const unsigned int yCenter,
const unsigned int threshold,
const unsigned int blackSquareSegmentMin,
const unsigned int blackSquareSegmentMax,
const unsigned int whiteSquareSegmentMin,
const unsigned int whiteSquareSegmentMax,
const unsigned int centerSegmentMin,
const unsigned int centerSegmentMax,
Scalar& symmetryScore,
Vector2* edgePoints);
390 static bool checkFinderPatternDirectional(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int paddingElements,
const unsigned int xCenter,
const unsigned int yCenter,
const Scalar angle,
const unsigned int threshold,
const unsigned int blackSquareSegmentMin,
const unsigned int blackSquareSegmentMax,
const unsigned int whiteSquareSegmentMin,
const unsigned int whiteSquareSegmentMax,
const unsigned int centerSegmentMin,
const unsigned int centerSegmentMax,
Vector2& topBorder,
Vector2& bottomBorder);
398 static inline bool isTransitionToBlack(
const uint8_t* pixel,
TransitionHistory& history);
406 static inline bool isTransitionToWhite(
const uint8_t* pixel,
TransitionHistory& history);
421 static inline unsigned int determineThreshold(
const uint8_t* yPosition,
const unsigned int segmentSize1,
const unsigned int segmentSize2,
const unsigned int segmentSize3,
const unsigned int segmentSize4,
const unsigned int segmentSize5);
451 centerIntensity_(centerIntensity),
452 grayThreshold_(grayThreshold),
453 symmetryScore_(symmetryScore),
454 cornersKnown_(false),
456 moduleSize_(length /
Scalar(7))
470 centerIntensity_(centerIntensity),
471 grayThreshold_(grayThreshold),
472 symmetryScore_(symmetryScore),
474 orientation_(orientation),
475 moduleSize_(moduleSize)
480 ocean_assert(
corners !=
nullptr);
559 : deltas_{ 0, 0, 0, 0, 0 }
571 return deltas_[0] + deltas_[1];
576 return deltas_[0] + deltas_[1] + deltas_[2];
581 return deltas_[0] + deltas_[1] + deltas_[2] + deltas_[3];
586 return deltas_[0] + deltas_[1] + deltas_[2] + deltas_[3] + deltas_[4];
591 deltas_[4] = deltas_[3];
592 deltas_[3] = deltas_[2];
593 deltas_[2] = deltas_[1];
594 deltas_[1] = deltas_[0];
595 deltas_[0] = newDelta;
609 const int currentDelta = int(*(pixel + 0) - *(pixel - 1));
626 history.
push(currentDelta);
633 const int currentDelta = int(*(pixel + 0) - *(pixel - 1));
650 history.
push(currentDelta);
655 inline unsigned int FinderPatternDetector::determineThreshold(
const uint8_t* yPosition,
const unsigned int segmentSize1,
const unsigned int segmentSize2,
const unsigned int segmentSize3,
const unsigned int segmentSize4,
const unsigned int segmentSize5)
657 unsigned int sumBlack = 0u;
658 unsigned int sumWhite = 0u;
660 sumWhite += *(yPosition - 1);
662 for (
unsigned int n = 0u; n < segmentSize1; ++n)
664 sumBlack += *yPosition++;
667 for (
unsigned int n = 0u; n < segmentSize2; ++n)
669 sumWhite += *yPosition++;
672 for (
unsigned int n = 0u; n < segmentSize3; ++n)
674 sumBlack += *yPosition++;
677 for (
unsigned int n = 0u; n < segmentSize4; ++n)
679 sumWhite += *yPosition++;
682 for (
unsigned int n = 0u; n < segmentSize5; ++n)
684 sumBlack += *yPosition++;
687 sumWhite += *yPosition;
689 const unsigned int averageBlack = sumBlack / (segmentSize1 + segmentSize3 + segmentSize5);
690 const unsigned int averageWhite = sumWhite / (segmentSize2 + segmentSize4 + 2u);
692 if (averageBlack + 2u >= averageWhite)
695 return (
unsigned int)(-1);
698 return (averageBlack + averageWhite + 1u) / 2u;
704 ocean_assert(finderPatternB.
corners() !=
nullptr && finderPatternA.
corners() !=
nullptr);
705 ocean_assert(distanceTolerance >= 0);
707 const Line2 linesB[4] =
718 const Scalar squareDistanceThreshold = (lineAB.
length() * distanceTolerance) * (lineAB.
length() * distanceTolerance);
720 for (
unsigned int n = 0u; n < 4u; ++n)
738 if (sqrDistanceCornerA0 < squareDistanceThreshold && sqrDistanceCornerA1 < squareDistanceThreshold)
740 if (linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[2]) < squareDistanceThreshold && linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[3]) < squareDistanceThreshold)
748 if (sqrDistanceCornerA1 < squareDistanceThreshold && sqrDistanceCornerA2 < squareDistanceThreshold)
750 if (linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[3]) < squareDistanceThreshold && linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[0]) < squareDistanceThreshold)
758 if (sqrDistanceCornerA2 < squareDistanceThreshold && sqrDistanceCornerA3 < squareDistanceThreshold)
760 if (linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[0]) < squareDistanceThreshold && linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[1]) < squareDistanceThreshold)
766 if (sqrDistanceCornerA3 < squareDistanceThreshold && sqrDistanceCornerA0 < squareDistanceThreshold)
768 if (linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[1]) < squareDistanceThreshold && linesB[(n + 2u) & 0b0011u].
sqrDistance(finderPatternA.
corners()[2]) < squareDistanceThreshold)
781 ocean_assert(finderPatternB.
corners() !=
nullptr && finderPatternA.
corners() !=
nullptr);
789 (finderPatternA.
corners()[2] - finderPatternA.
corners()[0]).normalizedOrZero(),
790 (finderPatternA.
corners()[3] - finderPatternA.
corners()[1]).normalizedOrZero()
793 unsigned int diagonalEdgeA = (
unsigned int)(-1);
794 unsigned int diagonalEdgeB = (
unsigned int)(-1);
796 if (
Numeric::abs(diagonalsA[0] * directionAB) >= angleThreshold)
800 else if (
Numeric::abs(diagonalsA[1] * directionAB) >= angleThreshold)
805 if (diagonalEdgeA >= 2u)
812 (finderPatternB.
corners()[2] - finderPatternB.
corners()[0]).normalizedOrZero(),
813 (finderPatternB.
corners()[3] - finderPatternB.
corners()[1]).normalizedOrZero()
816 if (
Numeric::abs(diagonalsB[0] * directionAB) >= angleThreshold)
820 else if (
Numeric::abs(diagonalsB[1] * directionAB) >= angleThreshold)
825 return diagonalEdgeA < 2u && diagonalEdgeB < 2u;
This class implements a simple history for previous pixel transitions (a sliding window of pixel tran...
Definition: FinderPatternDetector.h:215
int history2()
Returns the history with window size N.
Definition: FinderPatternDetector.h:569
int history3()
Returns the history with window size N.
Definition: FinderPatternDetector.h:574
void push(const int newDelta)
Adds a new delta object as most recent history.
Definition: FinderPatternDetector.h:589
void reset()
Resets the history object.
Definition: FinderPatternDetector.h:598
int history5()
Returns the history with window size N.
Definition: FinderPatternDetector.h:584
TransitionHistory()
Creates a new history object.
Definition: FinderPatternDetector.h:558
int history4()
Returns the history with window size N.
Definition: FinderPatternDetector.h:579
int history1()
Returns the history with window size N.
Definition: FinderPatternDetector.h:564
This class implements a detector for finder patterns which are part of QR Codes.
Definition: FinderPatternDetector.h:205
static bool isDiagonal(const FinderPattern &finderPatternA, const FinderPattern &finderPatternB, const Scalar angleTolerance=Numeric::deg2rad(9))
Returns true if a pair of finder patterns is in a diagonal configuration, i.e.
Definition: FinderPatternDetector.h:778
static constexpr int deltaThreshold
The intensity threshold between two successive pixels to count as a transition from dark to light (or...
Definition: FinderPatternDetector.h:209
static bool checkFinderPatternInNeighborhood(const uint8_t *const yFrame, const unsigned width, const unsigned height, const unsigned int paddingElements, const unsigned int xCenter, const unsigned int yCenter, const unsigned int threshold, const unsigned int blackSquareSegmentMin, const unsigned int blackSquareSegmentMax, const unsigned int whiteSquareSegmentMin, const unsigned int whiteSquareSegmentMax, const unsigned int centerSegmentMin, const unsigned int centerSegmentMax, Scalar &symmetryScore, Vector2 *edgePoints)
Performs a check around a given candidate location looking for a correct configuration of light and d...
static bool refineFinderPatternLocation(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, FinderPattern &finderPattern, const unsigned int yFramePaddingElements=0u)
Refine the location and corners of a finder pattern.
static IndexTriplets extractIndexTriplets(const FinderPatterns &finderPatterns, const Scalar distanceScaleTolerance=Scalar(0.175), const Scalar moduleSizeScaleTolerance=Scalar(0.35), const Scalar angleTolerance=Numeric::deg2rad(Scalar(9)))
Extract 3-tuples of finder patterns that form good (plausible) candidates for QR code symbols.
static bool isTransitionToBlack(const uint8_t *pixel, TransitionHistory &history)
Checks whether the given pixel is a transition-to-black pixel (whether the direct left neighbor is a ...
Definition: FinderPatternDetector.h:607
static bool checkFinderPatternDirectional(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int paddingElements, const unsigned int xCenter, const unsigned int yCenter, const Scalar angle, const unsigned int threshold, const unsigned int blackSquareSegmentMin, const unsigned int blackSquareSegmentMax, const unsigned int whiteSquareSegmentMin, const unsigned int whiteSquareSegmentMax, const unsigned int centerSegmentMin, const unsigned int centerSegmentMax, Vector2 &topBorder, Vector2 &bottomBorder)
Performs a check for a given candidate location in a specified direction (yielding 2 edge points)
static FinderPatterns detectFinderPatterns(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int minimumDistance=10u, const unsigned int paddingElements=0u, Worker *worker=nullptr)
Detects finder patterns of a QR code in a 8 bit grayscale image.
static unsigned int determineThreshold(const uint8_t *yPosition, const unsigned int segmentSize1, const unsigned int segmentSize2, const unsigned int segmentSize3, const unsigned int segmentSize4, const unsigned int segmentSize5)
Determines the gray threshold separating bright pixels form dark pixels.
Definition: FinderPatternDetector.h:655
static bool estimateFinderPatternCorners(const unsigned int xCenter, const unsigned int yCenter, const Vector2 *edgePoints, const unsigned int edgePointsSize, Vector2 &location, Vector2 *corners, Vector2 &orientation, Scalar &moduleSize, const Scalar edgePointDistanceTolerance=2.25, const Scalar maxEdgeLineDistance=1.5)
Estimates the locations of the corners of finder pattern and computes the dominant orientation of the...
static bool isParallel(const FinderPattern &finderPatternA, const FinderPattern &finderPatternB, const Scalar distanceTolerance=Scalar(0.05))
Returns true if a pair of finder patterns is in parallel configuration, i.e., if one is above/below/l...
Definition: FinderPatternDetector.h:701
static void detectFinderPatternsSubset(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, FinderPatterns *finderPatterns, Lock *multiThreadLock, const unsigned int paddingElements, const unsigned int firstRow, const unsigned int numberRows)
Detects finder patterns of QR codes in subregion of a given 8 bit grayscale image.
static void detectFinderPatternInRow(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, const unsigned int y, FinderPatterns &finderPatterns, const unsigned int paddingElements)
Detects finder patterns of QR codes in a single row of an grayscale image.
static bool isTransitionToWhite(const uint8_t *pixel, TransitionHistory &history)
Checks whether the given pixel is a transition-to-white pixel (whether the direct left neighbor is a ...
Definition: FinderPatternDetector.h:631
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
Scalar symmetryScore() const
Returns the symmetry score that was determined when this finder pattern was detected.
Definition: FinderPatternDetector.h:520
const Vector2 & orientation() const
Returns the dominant orientation of this finder pattern.
Definition: FinderPatternDetector.h:542
Vector2 corners_[4]
The four corners of this finder pattern; points are stored in counter-clockwise order but no guarante...
Definition: FinderPatternDetector.h:179
bool cornersKnown_
True if the four corners of this finder pattern are known, otherwise false.
Definition: FinderPatternDetector.h:176
Scalar length() const
Returns the radius of the finder pattern.
Definition: FinderPatternDetector.h:500
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
unsigned int grayThreshold() const
Returns the threshold that was used for the detection of this finder pattern.
Definition: FinderPatternDetector.h:510
Vector2 orientation_
Dominant orientation of this finder pattern.
Definition: FinderPatternDetector.h:182
bool isNormalReflectance() const
Returns whether this finder pattern is of normal reflectance.
Definition: FinderPatternDetector.h:548
static bool comesBefore(const FinderPattern &first, const FinderPattern &second)
Comparator to sort finder patterns based on their location in an image Pattern a comes before pattern...
Definition: FinderPatternDetector.h:553
Scalar symmetryScore_
The symmetry score of this finder pattern, range: [0, infinity) (lower score = higher symmetry)
Definition: FinderPatternDetector.h:173
Vector2 position_
The (center) position of the finder pattern within the camera frame.
Definition: FinderPatternDetector.h:161
Scalar moduleSize_
Module width (bit width) in pixels.
Definition: FinderPatternDetector.h:185
FinderPattern()
Creates an invalid finder pattern object.
Definition: FinderPatternDetector.h:442
Scalar length_
The edge length of the finder pattern in pixels, range: (0, infinity).
Definition: FinderPatternDetector.h:164
unsigned int grayThreshold_
The threshold that was used during the detection of this finder pattern.
Definition: FinderPatternDetector.h:170
unsigned int centerIntensity_
The intensity value that has been measured in the center of the finder pattern.
Definition: FinderPatternDetector.h:167
Scalar moduleSize() const
Returns the width of a module (= bit) in pixels.
Definition: FinderPatternDetector.h:515
unsigned int centerIntensity() const
Returns the intensity value that was measured in the center of the finder pattern.
Definition: FinderPatternDetector.h:505
static bool isBlack(const T &intensityValue, const T &threshold)
Determines whether an intensity value is black according to threshold value.
Definition: TransitionDetector.h:181
This class implements an infinite line in 2D space.
Definition: Line2.h:83
T sqrDistance(const VectorT2< T > &point) const
Returns the square distance between the line and a given point.
Definition: Line2.h:498
This class implements a recursive lock object.
Definition: Lock.h:31
This class provides basic numeric functionalities.
Definition: Numeric.h:57
static constexpr T deg2rad(const T deg)
Converts deg to rad.
Definition: Numeric.h:3232
static T abs(const T value)
Returns the absolute value of a given value.
Definition: Numeric.h:1220
static constexpr bool isEqualEps(const T value)
Returns whether a value is smaller than or equal to a small epsilon.
Definition: Numeric.h:2087
static T cos(const T value)
Returns the cosine of a given value.
Definition: Numeric.h:1584
const T & x() const noexcept
Returns the x value.
Definition: Vector2.h:698
const T & y() const noexcept
Returns the y value.
Definition: Vector2.h:710
VectorT2< T > normalized() const
Returns the normalized vector.
Definition: Vector2.h:558
VectorT2< T > normalizedOrZero() const
Returns the normalized vector.
Definition: Vector2.h:572
T length() const
Returns the length of the vector.
Definition: Vector2.h:615
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
unsigned int sqrDistance(const char first, const char second)
Returns the square distance between two values.
Definition: base/Utilities.h:1089
std::array< FinderPattern, 3 > FinderPatternTriplet
Definition of a 3-tuple of finder patterns.
Definition: FinderPatternDetector.h:198
std::vector< FinderPattern > FinderPatterns
Definition of a vector holding finder pattern.
Definition: FinderPatternDetector.h:192
std::vector< IndexTriplet > IndexTriplets
Definition of a vector index triplets.
Definition: FinderPatternDetector.h:51
std::array< unsigned int, 3 > IndexTriplet
Definition of a triplet of indices.
Definition: FinderPatternDetector.h:45
float Scalar
Definition of a scalar type.
Definition: Math.h:128
LineT2< Scalar > Line2
Definition of the Line2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition: Line2.h:21
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