66template <
typename TPixel>
136 RowSegmenter(
const TPixel* pixelData,
const size_t pixelDataSize,
const TGradient minimumGradient,
const bool isNormalReflectance);
233template <
typename TPixel>
239template <
typename TPixel>
242 return deltas_[0] + deltas_[1];
245template <
typename TPixel>
248 return deltas_[0] + deltas_[1] + deltas_[2];
251template <
typename TPixel>
254 deltas_[2] = deltas_[1];
255 deltas_[1] = deltas_[0];
256 deltas_[0] = newDelta;
259template <
typename TPixel>
267template <
typename TPixel>
270 size_(pixelDataSize),
274 if (isNormalReflectance)
288template <
typename TPixel>
291 return pixelData_ !=
nullptr && size_ != 0 && minimumGradient_ >
TGradient(0) && isTransitionToForeground_ !=
nullptr && isTransitionToBackground_ !=
nullptr;
294template <
typename TPixel>
303 segmentData_.clear();
305 transitionHistory_.reset();
308 ocean_assert(position_ != 0);
310 while (position_ < size_ && !isTransitionToForeground_(pixelData_ + position_, minimumGradient_, transitionHistory_))
315 if (position_ < size_)
317 segmentPosition_ = position_;
325template <
typename TPixel>
333 if (numberSegments <= segmentData_.size())
343 ocean_assert(position_ > 0u);
350 const TPixel grayThreshold_ = (pixelData_[position_ - 1] + pixelData_[position_]) / 2u;
352 while (segmentPosition_ < size_ && numberSegments > segmentData_.size())
354 const bool atForeground = segmentData_.size() % 2 == 0;
356 size_t nextSegmentPosition = segmentPosition_ + 1;
359 const bool scanForDarkPixels = atForeground == isNormalReflectance_;
361 if (scanForDarkPixels)
363 while (nextSegmentPosition < size_ && pixelData_[nextSegmentPosition] < grayThreshold_)
365 nextSegmentPosition++;
370 while (nextSegmentPosition < size_ && pixelData_[nextSegmentPosition] >= grayThreshold_)
372 nextSegmentPosition++;
376 ocean_assert(nextSegmentPosition >= segmentPosition_);
377 const uint32_t segmentSize = uint32_t(nextSegmentPosition - segmentPosition_);
379 if (segmentSize == 0)
384 segmentData_.emplace_back(segmentSize);
385 segmentPosition_ = nextSegmentPosition;
392 while (segmentPosition_ < size_ && numberSegments > segmentData_.size())
395 const bool atForeground = segmentData_.size() % 2 == 0;
401 isNextTransition = isTransitionToBackground_;
405 isNextTransition = isTransitionToForeground_;
408 size_t nextSegmentPosition = segmentPosition_ + 1u;
410 while (nextSegmentPosition < size_ && !isNextTransition(pixelData_ + nextSegmentPosition, minimumGradient_, transitionHistory_))
412 ++nextSegmentPosition;
415 ocean_assert(nextSegmentPosition >= segmentPosition_);
416 const uint32_t segmentSize = uint32_t(nextSegmentPosition - segmentPosition_);
418 if (segmentSize == 0)
423 segmentData_.emplace_back(segmentSize);
424 segmentPosition_ = nextSegmentPosition;
428 if (numberSegments <= segmentData_.size())
453 DF_ENABLE_MULTIPLE_SCANLINE_DIRECTIONS = 1u << 0u,
455 DF_ENABLE_INVERTED_REFLECTANCE = 1u << 1u,
457 DF_ENABLE_SCANLINE_MIRRORING = 1u << 2u,
459 DF_ENABLE_MULTI_CODE_DETECTION = 1u << 3u,
461 DF_ENABLE_MULTI_CODE_DETECTION_WITH_DUPLICATES = 1u << 4u | DF_ENABLE_MULTI_CODE_DETECTION,
463 DF_ENABLE_EVERYTHING = 0xFFFFFFFFu
551 static FiniteLines2 computeScanlines(
const unsigned int frameWidth,
const unsigned frameHeight,
const Vector2& scanlineDirection,
const unsigned int scanlineSpacing,
const unsigned int frameBorder,
const unsigned int minimumScanlineLength);
572 template <
bool tIsNormalReflectance>
582template <
typename TPixel>
588template <
typename TPixel>
594template <
typename TPixel>
600template <
typename TPixel>
603 if (position >= size_)
605 ocean_assert(
false &&
"Invalid position value");
609 position_ = position;
610 segmentPosition_ = position_;
611 transitionHistory_.reset();
616template <
typename TPixel>
619 ocean_assert(pixel !=
nullptr);
620 ocean_assert(gradientThreshold >
TGradient(0));
624 bool isTransition =
false;
626 if (gradient < -gradientThreshold)
632 if (gradient + history.
history1() < -gradientThreshold ||
633 gradient + history.
history2() < -(gradientThreshold * 5 / 4)||
634 gradient + history.
history3() < -(gradientThreshold * 6 / 4))
640 history.
push(gradient);
645template <
typename TPixel>
648 ocean_assert(pixel !=
nullptr);
649 ocean_assert(gradientThreshold >
TGradient(0));
653 bool isTransition =
false;
655 if (gradient > gradientThreshold)
661 if (gradient + history.
history1() > gradientThreshold ||
662 gradient + history.
history2() > (gradientThreshold * 5 / 4)||
663 gradient + history.
history3() > (gradientThreshold * 6 / 4))
669 history.
push(gradient);
Definition of an observation of a barcode in 2D.
Definition BarcodeDetector2D.h:470
Observation()=default
Creates an invalid observation.
const FiniteLine2 & location() const
Returns the location of the observation.
FiniteLine2 location_
The location of the observation.
Definition BarcodeDetector2D.h:492
Observation(const Vector2 &startPoint, const Vector2 &endPoint)
Create an observation from points.
This class implements a detector for barcodes.
Definition BarcodeDetector2D.h:441
static FiniteLines2 computeScanlines(const unsigned int frameWidth, const unsigned frameHeight, const Vector2 &scanlineDirection, const unsigned int scanlineSpacing, const unsigned int frameBorder, const unsigned int minimumScanlineLength)
Computes the locations of the scan lines for a given direction.
static Vector2 computeDirectionVector(const Scalar angle, const Scalar length=Scalar(1))
Computes a vector pointing at a specific angle on a unit circle.
static bool isForegroundPixel(const uint8_t pixelValue, const uint8_t grayThreshold)
Checks if a given pixel is a foreground pixel.
static ParserFunctionSet getParserFunctions(const BarcodeTypeSet &barcodeTypeSet)
Returns the set of all available parser function pointers.
static Barcodes detectBarcodes(const Frame &yFrame, const uint32_t detectionFeatures=DF_STANDARD, const BarcodeTypeSet &enabledBarcodeTypes=BarcodeTypeSet(), const unsigned int scanlineSpacing=25u, Observations *observations=nullptr, FiniteLines2 *scanlines=nullptr)
Detects barcodes in an 8-bit grayscale image.
std::unordered_set< ParserFunction > ParserFunctionSet
Definition of a set of parser functions.
Definition BarcodeDetector2D.h:502
std::vector< Observation > Observations
Definition of a vector of observations.
Definition BarcodeDetector2D.h:496
bool(*)(const uint32_t *segmentData, const size_t size, Barcode &barcode, IndexPair32 &xCoordinates) ParserFunction
Definition of a function pointer for parser functions which detect the actual barcodes.
Definition BarcodeDetector2D.h:499
static bool extractScanlineData(const Frame &yFrame, const FiniteLine2 &scanline, ScanlineData &scanlineData, CV::PixelPositionsI &scanlinePositions, const unsigned int minimumScanlineLength=0u)
Extracts the data of scan line specified by two points.
DetectionFeatures
Definition of optional detection features.
Definition BarcodeDetector2D.h:449
static bool computeFrameIntersection(const unsigned int frameWidth, const unsigned frameHeight, const unsigned int frameBorder, const Line2 &line, CV::PixelPositionI &point0, CV::PixelPositionI &point1)
Computes the intersection points of a frame and an intersecting infinite line.
Definition of a barcode.
Definition Barcode.h:52
This class implements a simple history for previous pixel transitions (a sliding window of pixel tran...
Definition BarcodeDetector2D.h:80
TGradient history2()
Returns the history with window size N.
Definition BarcodeDetector2D.h:240
TGradient history3()
Returns the history with window size N.
Definition BarcodeDetector2D.h:246
TGradient history1()
Returns the history with window size N.
Definition BarcodeDetector2D.h:234
void reset()
Resets the history object.
Definition BarcodeDetector2D.h:260
TransitionHistory()=default
Creates a new history object.
void push(const TGradient newDelta)
Adds a new delta object as most recent history.
Definition BarcodeDetector2D.h:252
TGradient deltas_[3]
The most recent deltas.
Definition BarcodeDetector2D.h:121
This class converts raw pixel data into binary segments.
Definition BarcodeDetector2D.h:68
RowSegmenter(const TPixel *pixelData, const size_t pixelDataSize, const TGradient minimumGradient, const bool isNormalReflectance)
Creates a segmenter object for a buffer of raw pixel data.
Definition BarcodeDetector2D.h:268
size_t size_
The size of the raw pixel data in elements.
Definition BarcodeDetector2D.h:212
static bool isTransitionLightToDark(const TPixel *pixel, const TGradient minimumGradient, TransitionHistory &history)
Checks if the specified pixel is a transition from light to dark pixels.
Definition BarcodeDetector2D.h:617
bool prepareSegments(const size_t numberSegments)
Prepares a batch of segments.
Definition BarcodeDetector2D.h:326
bool isValid() const
Returns if this segmenter is valid.
Definition BarcodeDetector2D.h:289
TransitionHistory transitionHistory_
The object that holds the recent pixel history.
Definition BarcodeDetector2D.h:230
size_t size() const
Returns the size of the raw pixel data that is handled by this object.
Definition BarcodeDetector2D.h:589
bool(*)(const TPixel *, const TGradient, TransitionHistory &) IsTransitionFunc
Definition of a function pointer for function that determine intensity transitions between back- and ...
Definition BarcodeDetector2D.h:125
const TPixel * pixelData_
The pointer to the raw pixel data that will be processed by this object.
Definition BarcodeDetector2D.h:209
SegmentData segmentData_
The memory holding the current segments.
Definition BarcodeDetector2D.h:227
typename DifferenceValueTyper< TPixel >::Type TGradient
Definition BarcodeDetector2D.h:72
bool findNextTransitionToForeground()
Finds the next transition from background to foreground in the raw pixel data.
Definition BarcodeDetector2D.h:295
IsTransitionFunc isTransitionToBackground_
A pointer to the function that checks if there is a transition from foreground to background (this de...
Definition BarcodeDetector2D.h:206
size_t position_
The current position of the segmenter in the raw pixel data.
Definition BarcodeDetector2D.h:221
bool setPosition(const size_t position)
Sets the position of the segmenter in the raw pixel data.
Definition BarcodeDetector2D.h:601
static bool isTransitionDarkToLight(const TPixel *pixel, const TGradient minimumGradient, TransitionHistory &history)
Checks if the specified pixel is a transition from dark to light pixels.
Definition BarcodeDetector2D.h:646
size_t position() const
Returns the current position of the segmenter in the raw pixel data.
Definition BarcodeDetector2D.h:595
size_t segmentPosition_
The position of the segmenter in the raw pixel data when creating new segments (thresholding),...
Definition BarcodeDetector2D.h:224
IsTransitionFunc isTransitionToForeground_
A pointer to the function that checks if there is a transition from background to foreground (this de...
Definition BarcodeDetector2D.h:203
const SegmentData & segmentData() const
Returns the current segment data.
Definition BarcodeDetector2D.h:583
TGradient minimumGradient_
The minimum value of the pixel gradient that must be exceed for it count as a intensity transition.
Definition BarcodeDetector2D.h:215
bool isNormalReflectance_
True, if the foreground is darker than the background; false, if the reflectance is inverted.
Definition BarcodeDetector2D.h:218
This class implements a 2D pixel position with pixel precision.
Definition PixelPosition.h:63
T Type
Definition of the data type for the signed difference value.
Definition DataType.h:176
This class implements Ocean's image class.
Definition Frame.h:1969
This class implements an infinite line in 2D space.
Definition Line2.h:83
std::pair< Index32, Index32 > IndexPair32
Definition of a pair holding 32 bit indices.
Definition Base.h:138
std::vector< PixelPositionI > PixelPositionsI
Definition of a vector holding pixel positions (with positive and negative coordinate values).
Definition PixelPosition.h:53
std::vector< uint8_t > ScanlineData
Definition of scan line data, i.e., a sequence of raw pixel data.
Definition Barcodes.h:59
std::vector< uint32_t > SegmentData
Definition of segment data, i.e., a sequence of lengths of binary, alternating foreground and backgro...
Definition Barcodes.h:65
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition FiniteLine2.h:57
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