66template <
typename TPixel>
136 RowSegmenter(
const TPixel* pixelData,
const size_t pixelDataSize,
const TGradient minimumGradient,
const bool isNormalReflectance);
233template <
typename TPixel>
239template <
typename TPixel>
245template <
typename TPixel>
251template <
typename TPixel>
259template <
typename TPixel>
267template <
typename TPixel>
270 size_(pixelDataSize),
274 if (isNormalReflectance)
288template <
typename TPixel>
294template <
typename TPixel>
325template <
typename TPixel>
352 while (segmentPosition_ < size_ && numberSegments >
segmentData_.size())
361 if (scanForDarkPixels)
363 while (nextSegmentPosition <
size_ &&
pixelData_[nextSegmentPosition] < grayThreshold_)
365 nextSegmentPosition++;
370 while (nextSegmentPosition <
size_ &&
pixelData_[nextSegmentPosition] >= grayThreshold_)
372 nextSegmentPosition++;
377 const uint32_t segmentSize = uint32_t(nextSegmentPosition -
segmentPosition_);
379 if (segmentSize == 0)
392 while (segmentPosition_ < size_ && numberSegments >
segmentData_.size())
412 ++nextSegmentPosition;
416 const uint32_t segmentSize = uint32_t(nextSegmentPosition -
segmentPosition_);
418 if (segmentSize == 0)
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>
605 ocean_assert(
false &&
"Invalid position value");
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);
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
@ DF_ENABLE_INVERTED_REFLECTANCE
Enables the search for barcodes that use inverted reflectance.
Definition BarcodeDetector2D.h:455
@ DF_ENABLE_MULTI_CODE_DETECTION
Enable the detection of multiple codes, otherwise the detection will stop after the first detected ba...
Definition BarcodeDetector2D.h:459
@ DF_ENABLE_MULTI_CODE_DETECTION_WITH_DUPLICATES
Enable the detection of duplicate codes; this will also enable the detection of multiple codes.
Definition BarcodeDetector2D.h:461
@ DF_STANDARD
Standard features that should be sufficient for most cases (excluding all the cases below).
Definition BarcodeDetector2D.h:451
@ DF_ENABLE_SCANLINE_MIRRORING
Enables the detection of barcodes which are mirrored (e.g. when held up-side-down).
Definition BarcodeDetector2D.h:457
@ DF_ENABLE_EVERYTHING
Enable all of the available extra features.
Definition BarcodeDetector2D.h:463
@ DF_ENABLE_MULTIPLE_SCANLINE_DIRECTIONS
Enables additional scan line directions, i.e. besides horizontal lines, there will also be scan lines...
Definition BarcodeDetector2D.h:453
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
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
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
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
PixelPositionT< int > PixelPositionI
Definition of a PixelPosition object with a data type allowing positive and negative coordinate value...
Definition PixelPosition.h:39
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
LineT2< Scalar > Line2
Definition of the Line2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with single o...
Definition Line2.h:28
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
FiniteLineT2< Scalar > FiniteLine2
Definition of the FiniteLine2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with si...
Definition FiniteLine2.h:28
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition FiniteLine2.h:57
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Barcode > Barcodes
Definition of a vector of barcodes.
Definition Barcode.h:28
std::unordered_set< BarcodeType > BarcodeTypeSet
Definition of a set of barcode types.
Definition Barcode.h:45
Namespace of the CV Detector library.
Definition Barcode.h:19
Namespace of the CV library.
Definition Advanced.h:17
The namespace covering the entire Ocean framework.
Definition Accessor.h:15