66 template <
typename TPixel>
136 RowSegmenter(
const TPixel* pixelData,
const size_t pixelDataSize,
const TGradient minimumGradient,
const bool isNormalReflectance);
230 template <
typename TPixel>
236 template <
typename TPixel>
239 return deltas_[0] + deltas_[1];
242 template <
typename TPixel>
245 return deltas_[0] + deltas_[1] + deltas_[2];
248 template <
typename TPixel>
251 deltas_[2] = deltas_[1];
252 deltas_[1] = deltas_[0];
253 deltas_[0] = newDelta;
256 template <
typename TPixel>
264 template <
typename TPixel>
267 size_(pixelDataSize),
270 if (isNormalReflectance)
284 template <
typename TPixel>
287 return pixelData_ !=
nullptr && size_ != 0 && minimumGradient_ >
TGradient(0) && isTransitionToForeground_ !=
nullptr && isTransitionToBackground_ !=
nullptr;
290 template <
typename TPixel>
299 segmentData_.clear();
301 transitionHistory_.reset();
304 ocean_assert(position_ != 0);
306 while (position_ < size_ && !isTransitionToForeground_(pixelData_ + position_, minimumGradient_, transitionHistory_))
311 if (position_ < size_)
313 segmentPosition_ = position_;
321 template <
typename TPixel>
329 if (numberSegments <= segmentData_.size())
339 const TPixel grayThreshold_ = (pixelData_[position_ - 1] + pixelData_[position_]) / 2u;
341 while (segmentPosition_ < size_ && numberSegments > segmentData_.size())
343 const bool atForeground = segmentData_.size() % 2 == 0;
345 size_t nextSegmentPosition = segmentPosition_ + 1;
349 while (nextSegmentPosition < size_ && pixelData_[nextSegmentPosition] < grayThreshold_)
351 nextSegmentPosition++;
356 while (nextSegmentPosition < size_ && pixelData_[nextSegmentPosition] >= grayThreshold_)
358 nextSegmentPosition++;
362 ocean_assert(nextSegmentPosition >= segmentPosition_);
363 const uint32_t segmentSize = uint32_t(nextSegmentPosition - segmentPosition_);
365 if (segmentSize == 0)
370 segmentData_.emplace_back(segmentSize);
371 segmentPosition_ = nextSegmentPosition;
378 while (segmentPosition_ < pixelDataSize_ && numberSegments > segmentData_.size())
381 const bool atForeground = segmentData_.size() % 2 == 0;
383 IsTransitionFunc isNextTransition =
nullptr;
387 isNextTransition = isTransitionToBackground_;
391 isNextTransition = isTransitionToForeground_;
394 size_t nextSegmentPosition = segmentPosition_ + 1u;
396 while (nextSegmentPosition < pixelDataSize_ && !isNextTransition(pixelData_ + nextSegmentPosition, minimumGradient_, transitionHistory_))
398 ++nextSegmentPosition;
401 ocean_assert(nextSegmentPosition >= segmentPosition_);
402 const uint32_t segmentSize = uint32_t(nextSegmentPosition - segmentPosition_);
404 if (segmentSize == 0)
409 segmentData_.emplace_back(segmentSize);
410 segmentPosition_ = nextSegmentPosition;
414 if (numberSegments <= segmentData_.size())
439 DF_ENABLE_MULTIPLE_SCANLINE_DIRECTIONS = 1u << 0u,
441 DF_ENABLE_INVERTED_REFLECTANCE = 1u << 1u,
443 DF_ENABLE_SCANLINE_MIRRORING = 1u << 2u,
445 DF_ENABLE_MULTI_CODE_DETECTION = 1u << 3u,
447 DF_ENABLE_MULTI_CODE_DETECTION_WITH_DUPLICATES = 1u << 4u | DF_ENABLE_MULTI_CODE_DETECTION,
449 DF_ENABLE_EVERYTHING = 0xFFFFFFFFu
485 typedef bool (*ParserFunction)(
const uint32_t* segmentData,
const size_t size,
Barcode& barcode,
IndexPair32& xCoordinates);
537 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);
558 template <
bool tIsNormalReflectance>
568 template <
typename TPixel>
574 template <
typename TPixel>
580 template <
typename TPixel>
586 template <
typename TPixel>
589 if (position >= size_)
591 ocean_assert(
false &&
"Invalid position value");
595 position_ = position;
596 segmentPosition_ = position_;
597 transitionHistory_.reset();
602 template <
typename TPixel>
605 ocean_assert(pixel !=
nullptr);
606 ocean_assert(gradientThreshold >
TGradient(0));
610 bool isTransition =
false;
612 if (gradient < -gradientThreshold)
618 if (gradient + history.
history1() < -gradientThreshold ||
619 gradient + history.
history2() < -(gradientThreshold * 5 / 4)||
620 gradient + history.
history3() < -(gradientThreshold * 6 / 4))
626 history.
push(gradient);
631 template <
typename TPixel>
634 ocean_assert(pixel !=
nullptr);
635 ocean_assert(gradientThreshold >
TGradient(0));
639 bool isTransition =
false;
641 if (gradient > gradientThreshold)
647 if (gradient + history.
history1() > gradientThreshold ||
648 gradient + history.
history2() > (gradientThreshold * 5 / 4)||
649 gradient + history.
history3() > (gradientThreshold * 6 / 4))
655 history.
push(gradient);
Definition of an observation of a barcode in 2D.
Definition: BarcodeDetector2D.h:456
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:478
Observation(const Vector2 &startPoint, const Vector2 &endPoint)
Create an observation from points.
This class implements a detector for barcodes.
Definition: BarcodeDetector2D.h:427
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.
std::vector< Observation > Observations
Definition of a vector of observations.
Definition: BarcodeDetector2D.h:482
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:488
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:435
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:237
TGradient history3()
Returns the history with window size N.
Definition: BarcodeDetector2D.h:243
TGradient history1()
Returns the history with window size N.
Definition: BarcodeDetector2D.h:231
void reset()
Resets the history object.
Definition: BarcodeDetector2D.h:257
TransitionHistory()=default
Creates a new history object.
void push(const TGradient newDelta)
Adds a new delta object as most recent history.
Definition: BarcodeDetector2D.h:249
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:265
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:603
bool prepareSegments(const size_t numberSegments)
Prepares a batch of segments.
Definition: BarcodeDetector2D.h:322
bool isValid() const
Returns if this segmenter is valid.
Definition: BarcodeDetector2D.h:285
TransitionHistory transitionHistory_
The object that holds the recent pixel history.
Definition: BarcodeDetector2D.h:227
DifferenceValueTyper< TPixel >::Type TGradient
Definition: BarcodeDetector2D.h:72
size_t size() const
Returns the size of the raw pixel data that is handled by this object.
Definition: BarcodeDetector2D.h:575
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:224
bool(* IsTransitionFunc)(const TPixel *, const TGradient, TransitionHistory &)
Definition of a function pointer for function that determine intensity transitions between back- and ...
Definition: BarcodeDetector2D.h:125
bool findNextTransitionToForeground()
Finds the next transition from background to foreground in the raw pixel data.
Definition: BarcodeDetector2D.h:291
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:218
bool setPosition(const size_t position)
Sets the position of the segmenter in the raw pixel data.
Definition: BarcodeDetector2D.h:587
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:632
size_t position() const
Returns the current position of the segmenter in the raw pixel data.
Definition: BarcodeDetector2D.h:581
size_t segmentPosition_
The position of the segmenter in the raw pixel data when creating new segments (thresholding),...
Definition: BarcodeDetector2D.h:221
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:569
TGradient minimumGradient_
The minimum value of the pixel gradient that must be exceed for it count as a intensity transition.
Definition: BarcodeDetector2D.h:215
This class implements a 2D pixel position with pixel precision.
Definition: PixelPosition.h:65
This class is a helper class allowing to define the signed difference data type of a given type.
Definition: DataType.h:169
This class implements Ocean's image class.
Definition: Frame.h:1792
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:55
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
std::vector< uint8_t > ScanlineData
Definition of scan line data, i.e., a sequence of raw pixel data.
Definition: Barcodes.h:59
float Scalar
Definition of a scalar type.
Definition: Math.h:128
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:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15