8#ifndef META_OCEAN_CV_DETECTOR_SHAPE_DETECTOR_H
9#define META_OCEAN_CV_DETECTOR_SHAPE_DETECTOR_H
68 inline ShapeType type()
const;
74 inline unsigned int finiteLineIndex0()
const;
80 inline unsigned int finiteLineIndex1()
const;
87 inline unsigned int finiteLineIndex(
const unsigned int index)
const;
93 inline const Vector2& position()
const;
99 inline void setPosition(
const Vector2& position);
105 inline Scalar score()
const;
130 inline TwoLineShape(
const ShapeType shapeType,
const unsigned int finiteLineIndex0,
const unsigned int finiteLineIndex1,
const Vector2& position,
const Scalar score);
138 unsigned int finiteLineIndex0_ = (
unsigned int)(-1);
141 unsigned int finiteLineIndex1_ = (
unsigned int)(-1);
153 using TwoLineShapes = std::vector<const CV::Detector::ShapeDetector::TwoLineShape*>;
203 inline LShape(
const unsigned int finiteLineIndex0,
const unsigned int finiteLineIndex1,
const Vector2& position,
const Vector2& direction,
const Vector2& edgeLeft,
const Vector2& edgeRight,
const Scalar score);
209 inline const Vector2& edgeLeft()
const;
215 inline const Vector2& edgeRight()
const;
221 inline const Vector2& direction()
const;
273 inline TShape(
const unsigned int finiteLineIndex0,
const unsigned int finiteLineIndex1,
const Vector2& position,
const Vector2& direction,
const Scalar score =
Scalar(0));
279 inline const Vector2& direction()
const;
328 inline XShape(
const unsigned int finiteLineIndex0,
const unsigned int finiteLineIndex1,
const Vector2& position,
const Vector2& direction0,
const Vector2& direction1,
const Scalar score =
Scalar(0));
343 bool verifyShape(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const bool darkShape,
const unsigned int minimalValueRange,
const unsigned int sampleOffset = 2u,
const unsigned int samples = 4u,
const unsigned int yFramePaddingElements = 0u)
const;
349 inline const Vector2& direction0()
const;
355 inline const Vector2& direction1()
const;
426 static void detectShapes(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
LShapes& lShapes,
TShapes& tShapes,
XShapes& xShapes,
const int sign,
const double minimalThreshold = 5.0,
const unsigned int shapeWidth = 15u,
const unsigned int shapeHeight = 15u,
const unsigned int stepSize = 3u,
const unsigned int topBand = 4u,
const unsigned int bottomBand = 4u,
const unsigned int minimalDelta = 5u,
const unsigned int framePaddingElements = 0u);
451 static double tShapeResponse(
const int32_t* linedIntegralHorizontalSignedGradient,
const uint32_t* linedIntegralHorizontalAbsoluteGradient,
const int32_t* linedIntegralVerticalSignedGradient,
const uint32_t* linedIntegralVerticalAbsoluteGradient,
const unsigned int imageWidth,
const unsigned int imageHeight,
const unsigned int x,
const unsigned int y,
const int sign,
const unsigned int shapeWidth,
const unsigned int shapeHeight,
const unsigned int stepSize,
const unsigned int topBand,
const unsigned int bottomBand,
const unsigned int minimalDelta = 5u,
const unsigned int horizontalSignedGradientPaddingElements = 0u,
const unsigned int horizontalAbsoluteGradientPaddingElements = 0u,
const unsigned int verticalSignedGradientPaddingElements = 0u,
const unsigned int verticalAbsoluteGradientPaddingElements = 0u);
477 static void detectShapes(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
LShapes& lShapes,
TShapes& tShapes,
XShapes& xShapes,
const float minimalThreshold = 5.421f,
const unsigned int shapeWidth = 15u,
const unsigned int shapeHeight = 15u,
const unsigned int stepSize = 3u,
const unsigned int topBand = 4u,
const unsigned int bottomBand = 4u,
const unsigned int framePaddingElements = 0u);
496 static float tShapeResponse(
const uint32_t* linedIntegral,
const uint64_t* linedIntegralSquare,
const unsigned int width,
const unsigned int height,
const unsigned int x,
const unsigned int y,
const unsigned int shapeWidth,
const unsigned int shapeHeight,
const unsigned int stepSize,
const unsigned int topBand,
const unsigned int bottomBand,
const unsigned int linedIntegralPaddingElements = 0u,
const unsigned int linedIntegralSquaredPaddingElements = 0u);
507 static constexpr unsigned int shapeWidth_ = 15u;
510 static constexpr unsigned int shapeHeight_ = 15u;
513 static constexpr unsigned int shapeStepSize_ = 3u;
516 static constexpr unsigned int shapeBandSize_ = 4u;
519 static constexpr unsigned int shapeWidth_2_ = shapeWidth_ / 2u;
522 static constexpr unsigned int shapeStepSize_2_ = shapeStepSize_ / 2u;
524 static_assert(shapeWidth_ >= 1u && shapeWidth_ % 2u == 1u,
"Invalid shape width!");
525 static_assert(shapeHeight_ >= shapeStepSize_ + 1u,
"Invalid shape height!");
526 static_assert(shapeStepSize_ >= 1u && shapeStepSize_ % 2u == 1u,
"Invalid shape step size!");
527 static_assert(shapeBandSize_ >= 1u,
"Invalid shape band size!");
529 static_assert(shapeWidth_ >= shapeStepSize_ + 2u,
"Invalid shape height!");
530 static_assert(shapeHeight_ >= shapeStepSize_ + 1u,
"Invalid shape height!");
548 static void detectShapesF(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
LShapes& lShapes,
TShapes& tShapes,
XShapes& xShapes,
const int sign,
const float minimalThreshold = 6.0f,
const unsigned int framePaddingElements = 0u,
Frame* topDownResponseFrame =
nullptr,
Frame* bottomUpResponseFrame =
nullptr);
564 static void detectShapesI(
const uint8_t*
const yFrame,
const unsigned int width,
const unsigned int height,
LShapes& lShapes,
TShapes& tShapes,
XShapes& xShapes,
const int sign,
const float minimalThreshold = 6.0f,
const unsigned int framePaddingElements = 0u,
Frame* topDownResponseFrame =
nullptr,
Frame* bottomUpResponseFrame =
nullptr);
573 static inline unsigned int determineHorizontalResponseWidth(
const unsigned int width);
580 static inline unsigned int determineHorizontalResponseHeight(
const unsigned int height);
587 static inline unsigned int determineVerticalResponseWidth(
const unsigned int width);
594 static inline unsigned int determineVerticalResponseHeight(
const unsigned int height);
600 static constexpr int frameX_T_topDownHorizontalResponseX();
606 static constexpr int frameY_T_topDownHorizontalResponseY();
612 static constexpr int frameX_T_topDownVerticalResponseX();
618 static constexpr int frameY_T_topDownVerticalResponseY();
624 static constexpr int frameX_T_topDownResponseX();
630 static constexpr int frameY_T_topDownResponseY();
636 static constexpr int frameX_T_bottomUpHorizontalResponseX();
642 static constexpr int frameY_T_bottomUpHorizontalResponseY();
648 static constexpr int frameX_T_bottomUpVerticalResponseX();
654 static constexpr int frameY_T_bottomUpVerticalResponseY();
660 static constexpr int frameX_T_bottomUpResponseX();
666 static constexpr int frameY_T_bottomUpResponseY();
682 template <
bool tUseSIMD>
683 static void determineHorizontalResponsesI(
const uint32_t* linedIntegralAndSquared,
const unsigned int width,
const unsigned int height, int32_t* horizontalResponses,
const unsigned int linedIntegralAndSquaredPaddingElements = 0u,
const unsigned int horizontalResponsesPaddingElements = 0u);
701 template <
bool tUseSIMD>
702 static void determineHorizontalResponsesI(
const uint32_t* linedIntegral,
const uint64_t* linedIntegralSquared,
const unsigned int width,
const unsigned int height, int32_t* horizontalResponses,
const unsigned int linedIntegralPaddingElements = 0u,
const unsigned int linedIntegralSquaredPaddingElements = 0u,
const unsigned int horizontalResponsesPaddingElements = 0u);
717 template <
bool tSquaredResponse>
718 static void determineHorizontalResponsesF(
const uint32_t* linedIntegralAndSquared,
const unsigned int width,
const unsigned int height,
float* horizontalResponses,
const unsigned int linedIntegralAndSquaredPaddingElements = 0u,
const unsigned int horizontalResponsesPaddingElements = 0u);
733 template <
bool tUseSIMD>
734 static void determineVerticalResponsesI(
const uint32_t* linedIntegralAndSquared,
const unsigned int width,
const unsigned int height, int32_t* verticalResponses,
const unsigned int linedIntegralAndSquaredPaddingElements = 0u,
const unsigned int verticalResponsesPaddingElements = 0u);
751 template <
bool tUseSIMD>
752 static void determineVerticalResponsesI(
const uint32_t* linedIntegral,
const uint64_t* linedIntegralSquared,
const unsigned int width,
const unsigned int height, int32_t* verticalResponses,
const unsigned int linedIntegralPaddingElements = 0u,
const unsigned int linedIntegralSquaredPaddingElements = 0u,
const unsigned int verticalResponsesPaddingElements = 0u);
767 template <
bool tSquaredResponse>
768 static void determineVerticalResponsesF(
const uint32_t* linedIntegralAndSquared,
const unsigned int width,
const unsigned int height,
float* verticalResponses,
const unsigned int linedIntegralAndSquaredPaddingElements = 0u,
const unsigned int verticalResponsesPaddingElements = 0u);
783 template <
bool tSquaredResponse,
bool tCreateResponseFrame = false>
799 template <
bool tSquaredResponse,
bool tCreateResponseFrame = false>
816 template <
bool tCreateResponseFrame = false>
826 static inline bool haveCorrectSign(
const int32_t sign,
const float horizontalResponse,
const float verticalResponse);
835 static inline bool haveCorrectSign(
const int32_t sign,
const int32_t horizontalResponse,
const int32_t verticalResponse);
852 static Rectangles detectAlignedRectangles(
const Frame& yFrame,
const unsigned int rectangleWidth,
const Scalar aspectRatio,
const Scalar aspectRatioTolerance =
Scalar(0.10),
const Scalar alignmentAngleTolerance = Numeric::deg2rad(35),
const bool sortRectangles =
true,
const unsigned int lineImageBorderDistanceThreshold = 5u,
const unsigned int perpendicularSampleDistance = 5u);
880 static void determineShapes(
const FiniteLines2& horizontalFiniteLines,
const FiniteLines2& verticalFiniteLines,
const unsigned int width,
const unsigned int height,
LShapes& lShapes,
TShapes& tShapes,
XShapes& xShapes,
const Scalar thresholdShortDistance =
Scalar(2),
const Scalar thresholdLongDistance =
Scalar(5),
const Scalar thresholdShapeAngle = Numeric::deg2rad(20),
const Scalar thresholdAngleXShape = Numeric::deg2rad(5));
901 template <
bool tAllowPerpendicularDirections>
902 static LShapes filterLShapesBasedOnDirection(
const LShapes& lShapes,
const Vector2 alignmentDirection,
const Scalar alignmentAngleThreshold = Numeric::deg2rad(15));
962 static Rectangles guessShapedRectanglesFromUpperCorners(
const LShapes& lShapes,
const Vector2& topLeftCornerDirection,
const Scalar aspectRatio,
const unsigned int imageHeight,
const unsigned int maxNumberOfCandidates,
const Scalar thresholdCornerDirectionAngle = Numeric::deg2rad(15),
const Scalar thresholdConnectedShapesAngle = Numeric::deg2rad(5),
const Scalar minimalRectangleWidth = 90,
const Scalar maximalRectangleWidth = 250,
const unsigned int numCandidatePairsToGeneratePerEdge = 1u,
const Scalar sideEdgeRatioMultiplier = 1.0);
973 static inline bool areLShapesConnected(
const LShape& lShapeA,
const LShape& lShapeB,
const Vector2& directionA,
const Vector2& directionB,
const Scalar thresholdAngleCos = Numeric::cos(Numeric::deg2rad(5)));
1006 static bool optimizeLineAlongEdge(
const Frame& yFrame,
const FiniteLine2& line,
Line2& optimizedLine,
const unsigned int perpendicularSampleDistance = 5u,
const unsigned int sampleLocations = 30u,
const unsigned int minimalValidSampleLocations = 5u,
const Scalars& sampleLocationsPercent =
Scalars());
1014 static inline bool hasGreaterArea(
const Rectangle& firstRectangle,
const Rectangle& secondRectangle);
1024 shapeType_(shapeType),
1025 finiteLineIndex0_((unsigned int)(-1)),
1026 finiteLineIndex1_((unsigned int)(-1)),
1027 position_(position),
1036 shapeType_(shapeType),
1037 finiteLineIndex0_(finiteLineIndex0),
1038 finiteLineIndex1_(finiteLineIndex1),
1039 position_(position),
1054 return finiteLineIndex0_;
1059 return finiteLineIndex1_;
1064 ocean_assert(index <= 1u);
1065 return index == 0u ? finiteLineIndex0() : finiteLineIndex1();
1075 position_ = position;
1091 edgeLeft_(edgeLeft),
1092 edgeRight_(edgeRight),
1093 direction_(direction)
1105 TwoLineShape(ST_SHAPE_L, finiteLineIndex0, finiteLineIndex1, position, score),
1106 edgeLeft_(edgeLeft),
1107 edgeRight_(edgeRight),
1108 direction_(direction)
1142 direction_(direction)
1148 TwoLineShape(ST_SHAPE_T, finiteLineIndex0, finiteLineIndex1, position, score),
1149 direction_(direction)
1167 direction0_(direction0),
1168 direction1_(direction1)
1176 TwoLineShape(ST_SHAPE_X, finiteLineIndex0, finiteLineIndex1, position, score),
1177 direction0_(direction0),
1178 direction1_(direction1)
1197 ocean_assert(width >= shapeWidth_);
1198 return width - shapeWidth_ + 1u;
1203 ocean_assert(height >= shapeBandSize_ * 2u + shapeStepSize_);
1204 return height - (shapeBandSize_ * 2u + shapeStepSize_) + 1u;
1209 ocean_assert(width >= shapeBandSize_ * 2u + shapeStepSize_);
1210 return width - (shapeBandSize_ * 2u + shapeStepSize_) + 1u;
1215 ocean_assert(height >= shapeHeight_ - shapeStepSize_);
1216 return height - (shapeHeight_ - shapeStepSize_) + 1u;
1221 return int(shapeWidth_2_);
1226 return int(shapeBandSize_ + shapeStepSize_2_);
1231 return int(shapeBandSize_ + shapeStepSize_2_);
1236 return -int(shapeStepSize_2_ + 1u);
1243 return frameX_T_topDownHorizontalResponseX() > frameX_T_topDownVerticalResponseX() ? frameX_T_topDownHorizontalResponseX() : frameX_T_topDownVerticalResponseX();
1250 return frameY_T_topDownHorizontalResponseY() > frameY_T_topDownVerticalResponseY() ? frameY_T_topDownHorizontalResponseY() : frameY_T_topDownVerticalResponseY();
1255 return int(shapeWidth_2_);
1260 return int(shapeBandSize_ + shapeStepSize_2_);
1265 return int(shapeBandSize_ + shapeStepSize_2_);
1270 return int(shapeHeight_ - shapeStepSize_2_ - 1u);
1277 return frameX_T_bottomUpHorizontalResponseX() > frameX_T_bottomUpVerticalResponseX() ? frameX_T_bottomUpHorizontalResponseX() : frameX_T_bottomUpVerticalResponseX();
1284 return frameY_T_bottomUpHorizontalResponseY() > frameY_T_bottomUpVerticalResponseY() ? frameY_T_bottomUpHorizontalResponseY() : frameY_T_bottomUpVerticalResponseY();
1291 return horizontalResponse < 0.0f && verticalResponse < 0.0f;
1295 return horizontalResponse > 0.0f && verticalResponse > 0.0f;
1299 ocean_assert(sign == 0);
1300 return (horizontalResponse < 0.0f && verticalResponse < 0.0f) || (horizontalResponse > 0.0f && verticalResponse > 0.0f);
1308 return horizontalResponse < 0 && verticalResponse < 0;
1312 return horizontalResponse > 0 && verticalResponse > 0;
1316 ocean_assert(sign == 0);
1317 return (horizontalResponse < 0 && verticalResponse < 0) || (horizontalResponse > 0 && verticalResponse > 0);
1321template <
bool tAllowPerpendicularDirections>
1324 ocean_assert(alignmentDirection.
isUnit());
1325 ocean_assert(alignmentAngleThreshold >= 0 && alignmentAngleThreshold <=
Numeric::pi_2());
1328 ocean_assert(perpendicularAlignmentDirection.
isUnit());
1333 filteredLShapes.reserve(lShapes.size());
1335 for (
const LShape& lShape : lShapes)
1337 if (
Numeric::abs(lShape.direction() * alignmentDirection) >= alginmentAngleThresholdCos
1338 || (tAllowPerpendicularDirections &&
Numeric::abs(lShape.direction() * perpendicularAlignmentDirection) >= alginmentAngleThresholdCos))
1340 filteredLShapes.push_back(lShape);
1344 return filteredLShapes;
1350 ocean_assert(directionA.
isUnit() && directionB.
isUnit());
1354 if (directionA * direction < thresholdAngleCos)
1360 if (-(directionB * direction) < thresholdAngleCos)
1371 ocean_assert(
Triangle2(firstRectangle[0], firstRectangle[1], firstRectangle[2]).isValid() &&
Triangle2(firstRectangle[2], firstRectangle[3], firstRectangle[0]).isValid());
1372 ocean_assert(
Triangle2(secondRectangle[0], secondRectangle[1], secondRectangle[2]).isValid() &&
Triangle2(secondRectangle[2], secondRectangle[3], secondRectangle[0]).isValid());
1374 const Scalar areaFirstRectangle =
Triangle2(firstRectangle[0], firstRectangle[1], firstRectangle[2]).area2() +
Triangle2(firstRectangle[2], firstRectangle[3], firstRectangle[0]).area2();
1375 const Scalar areaSecondRectangle =
Triangle2(secondRectangle[0], secondRectangle[1], secondRectangle[2]).area2() +
Triangle2(secondRectangle[2], secondRectangle[3], secondRectangle[0]).area2();
1377 return areaFirstRectangle > areaSecondRectangle;
This class implements an L-shape element like a corner of a rectangle.
Definition ShapeDetector.h:175
const Vector2 & edgeLeft() const
Returns the left edge of this L-shape.
Definition ShapeDetector.h:1119
Vector2 edgeLeft_
The left edge of this L-shape.
Definition ShapeDetector.h:226
Vector2 edgeRight_
The right edge of this L-shape.
Definition ShapeDetector.h:229
LShape()
Creates an invalid L-shape object.
Definition ShapeDetector.h:1083
Vector2 direction_
The direction of this L-shape.
Definition ShapeDetector.h:232
const Vector2 & direction() const
Returns the direction of this L-shape.
Definition ShapeDetector.h:1129
const Vector2 & edgeRight() const
Returns the right edge of this L-shape.
Definition ShapeDetector.h:1124
This class implements a shape detector mainly based on gradients.
Definition ShapeDetector.h:405
static double tShapeResponse(const int32_t *linedIntegralHorizontalSignedGradient, const uint32_t *linedIntegralHorizontalAbsoluteGradient, const int32_t *linedIntegralVerticalSignedGradient, const uint32_t *linedIntegralVerticalAbsoluteGradient, const unsigned int imageWidth, const unsigned int imageHeight, const unsigned int x, const unsigned int y, const int sign, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int stepSize, const unsigned int topBand, const unsigned int bottomBand, const unsigned int minimalDelta=5u, const unsigned int horizontalSignedGradientPaddingElements=0u, const unsigned int horizontalAbsoluteGradientPaddingElements=0u, const unsigned int verticalSignedGradientPaddingElements=0u, const unsigned int verticalAbsoluteGradientPaddingElements=0u)
Determines the detector response for an gradient-based T-shape detector which is axis aligned.
static void detectShapes(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const double minimalThreshold=5.0, const unsigned int shapeWidth=15u, const unsigned int shapeHeight=15u, const unsigned int stepSize=3u, const unsigned int topBand=4u, const unsigned int bottomBand=4u, const unsigned int minimalDelta=5u, const unsigned int framePaddingElements=0u)
Detects shapes in a given image.
This class implements a shape detector based on gradients and variance.
Definition ShapeDetector.h:503
static void determineResponsesI(const int32_t *horizontalResponses, const int32_t *verticalResponses, const unsigned int width, const unsigned int height, const int32_t sign, const uint32_t minimalSqrThreshold, CV::NonMaximumSuppressionT< uint32_t > &nonMaximumSuppressionTopDown, CV::NonMaximumSuppressionT< uint32_t > &nonMaximumSuppressionBottomUp, Frame *responseFrameTopDown=nullptr, Frame *responseFrameBottomUp=nullptr)
Determines the integer T-shape responses for the top-down and bottom-up direction.
static void determineTopDownResponsesF(const float *horizontalResponses, const float *verticalResponses, const unsigned int width, const unsigned int height, const int32_t sign, const float minimalThreshold, CV::NonMaximumSuppressionT< float > &nonMaximumSuppression, Frame *responseFrame=nullptr)
Determines the floating-point T-shape responses for the top-down direction.
static void determineVerticalResponsesI(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquared, const unsigned int width, const unsigned int height, int32_t *verticalResponses, const unsigned int linedIntegralPaddingElements=0u, const unsigned int linedIntegralSquaredPaddingElements=0u, const unsigned int verticalResponsesPaddingElements=0u)
Determines the integer vertical responses for the T-shape and stores the results in a given response ...
static constexpr int frameY_T_topDownResponseY()
Returns the translation offset in y-direction between the top-down response location and the frame.
Definition ShapeDetector.h:1246
static constexpr int frameX_T_bottomUpVerticalResponseX()
Returns the translation offset in x-direction between the vertical bottom-up response location and th...
Definition ShapeDetector.h:1263
static void detectShapesI(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const float minimalThreshold=6.0f, const unsigned int framePaddingElements=0u, Frame *topDownResponseFrame=nullptr, Frame *bottomUpResponseFrame=nullptr)
Detects shapes in a given image while applying integer precision.
static constexpr int frameX_T_topDownVerticalResponseX()
Returns the translation offset in x-direction between the vertical top-down response location and the...
Definition ShapeDetector.h:1229
static void determineVerticalResponsesI(const uint32_t *linedIntegralAndSquared, const unsigned int width, const unsigned int height, int32_t *verticalResponses, const unsigned int linedIntegralAndSquaredPaddingElements=0u, const unsigned int verticalResponsesPaddingElements=0u)
Determines the integer vertical responses for the T-shape and stores the results in a given response ...
static void determineVerticalResponsesF(const uint32_t *linedIntegralAndSquared, const unsigned int width, const unsigned int height, float *verticalResponses, const unsigned int linedIntegralAndSquaredPaddingElements=0u, const unsigned int verticalResponsesPaddingElements=0u)
Determines the floating-point vertical responses for the T-shape and stores the results in a given re...
static constexpr int frameX_T_topDownHorizontalResponseX()
Returns the translation offset in x-direction between the horizontal top-down response location and t...
Definition ShapeDetector.h:1219
static constexpr int frameY_T_bottomUpVerticalResponseY()
Returns the translation offset in y-direction between the vertical bottom-up response location and th...
Definition ShapeDetector.h:1268
static constexpr int frameY_T_bottomUpHorizontalResponseY()
Returns the translation offset in y-direction between the horizontal bottom-up response location and ...
Definition ShapeDetector.h:1258
static void determineHorizontalResponsesF(const uint32_t *linedIntegralAndSquared, const unsigned int width, const unsigned int height, float *horizontalResponses, const unsigned int linedIntegralAndSquaredPaddingElements=0u, const unsigned int horizontalResponsesPaddingElements=0u)
Determines the floating-point horizontal responses for the T-shape and stores the results in a given ...
static bool haveCorrectSign(const int32_t sign, const float horizontalResponse, const float verticalResponse)
Returns whether the sign of two responses matches the expected sign.
Definition ShapeDetector.h:1287
static constexpr int frameY_T_topDownVerticalResponseY()
Returns the translation offset in y-direction between the vertical top-down response location and the...
Definition ShapeDetector.h:1234
static unsigned int determineVerticalResponseWidth(const unsigned int width)
Returns the width of the vertical response frame.
Definition ShapeDetector.h:1207
static unsigned int determineHorizontalResponseHeight(const unsigned int height)
Returns the height of the horizontal response frame.
Definition ShapeDetector.h:1201
static void determineBottomUpResponsesF(const float *horizontalResponses, const float *verticalResponses, const unsigned int width, const unsigned int height, const int32_t sign, const float minimalThreshold, CV::NonMaximumSuppressionT< float > &nonMaximumSuppression, Frame *responseFrame=nullptr)
Determines the floating-point T-shape responses for the bottom-up direction.
static constexpr int frameY_T_bottomUpResponseY()
Returns the translation offset in y-direction between the bottom-up response location and the frame.
Definition ShapeDetector.h:1280
static void determineHorizontalResponsesI(const uint32_t *linedIntegralAndSquared, const unsigned int width, const unsigned int height, int32_t *horizontalResponses, const unsigned int linedIntegralAndSquaredPaddingElements=0u, const unsigned int horizontalResponsesPaddingElements=0u)
Determines the integer horizontal responses for the T-shape and stores the results in a given respons...
static void determineHorizontalResponsesI(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquared, const unsigned int width, const unsigned int height, int32_t *horizontalResponses, const unsigned int linedIntegralPaddingElements=0u, const unsigned int linedIntegralSquaredPaddingElements=0u, const unsigned int horizontalResponsesPaddingElements=0u)
Determines the integer horizontal responses for the T-shape and stores the results in a given respons...
static constexpr int frameX_T_bottomUpResponseX()
Returns the translation offset in x-direction between the bottom-up response location and the frame.
Definition ShapeDetector.h:1273
static unsigned int determineVerticalResponseHeight(const unsigned int height)
Returns the height of the vertical response frame.
Definition ShapeDetector.h:1213
static unsigned int determineHorizontalResponseWidth(const unsigned int width)
Returns the width of the horizontal response frame.
Definition ShapeDetector.h:1195
static constexpr int frameY_T_topDownHorizontalResponseY()
Returns the translation offset in y-direction between the horizontal top-down response location and t...
Definition ShapeDetector.h:1224
static constexpr int frameX_T_bottomUpHorizontalResponseX()
Returns the translation offset in x-direction between the horizontal bottom-up response location and ...
Definition ShapeDetector.h:1253
static constexpr int frameX_T_topDownResponseX()
Returns the translation offset in x-direction between the top-down response location and the frame.
Definition ShapeDetector.h:1239
static void detectShapesF(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const int sign, const float minimalThreshold=6.0f, const unsigned int framePaddingElements=0u, Frame *topDownResponseFrame=nullptr, Frame *bottomUpResponseFrame=nullptr)
Detects shapes in a given image while applying floating-point precision.
This class implements a shape detector mainly based on variance.
Definition ShapeDetector.h:458
static void detectShapes(const uint8_t *const yFrame, const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const float minimalThreshold=5.421f, const unsigned int shapeWidth=15u, const unsigned int shapeHeight=15u, const unsigned int stepSize=3u, const unsigned int topBand=4u, const unsigned int bottomBand=4u, const unsigned int framePaddingElements=0u)
Detects shapes in a given image.
static float tShapeResponse(const uint32_t *linedIntegral, const uint64_t *linedIntegralSquare, const unsigned int width, const unsigned int height, const unsigned int x, const unsigned int y, const unsigned int shapeWidth, const unsigned int shapeHeight, const unsigned int stepSize, const unsigned int topBand, const unsigned int bottomBand, const unsigned int linedIntegralPaddingElements=0u, const unsigned int linedIntegralSquaredPaddingElements=0u)
Determines the detector response for an variance-based T-shape detector which is axis aligned.
This class implements a T-shape element like a junction connecting two lines, with one line having th...
Definition ShapeDetector.h:249
Vector2 direction_
The direction of this T-shape.
Definition ShapeDetector.h:284
const Vector2 & direction() const
Returns the direction of this T-shape.
Definition ShapeDetector.h:1154
TShape()
Creates an invalid T-shape object.
Definition ShapeDetector.h:1134
This class implements the base class for all shapes based on two lines.
Definition ShapeDetector.h:44
void setPosition(const Vector2 &position)
Sets or changes the position of this shape.
Definition ShapeDetector.h:1073
TwoLineShape()
Creates an invalid shape.
Definition ShapeDetector.h:1017
ShapeType type() const
Returns the type of the shape.
Definition ShapeDetector.h:1047
Scalar score_
The score of this L-shape.
Definition ShapeDetector.h:147
Vector2 position_
The position of this shape.
Definition ShapeDetector.h:144
unsigned int finiteLineIndex(const unsigned int index) const
Returns the index of the first or second finite line.
Definition ShapeDetector.h:1062
unsigned int finiteLineIndex1() const
Returns the index of the second finite line.
Definition ShapeDetector.h:1057
ShapeType shapeType_
The shape's type.
Definition ShapeDetector.h:135
ShapeType
Definition of individual shape types.
Definition ShapeDetector.h:51
@ ST_INVALID
An invalid shape type.
Definition ShapeDetector.h:53
Scalar score() const
Returns the sore of this shape.
Definition ShapeDetector.h:1078
unsigned int finiteLineIndex0() const
Returns the index of the first finite line.
Definition ShapeDetector.h:1052
const Vector2 & position() const
Returns the position of this shape.
Definition ShapeDetector.h:1068
This class implements a X-shape element like a crossing of two lines, with both lines not crossing ne...
Definition ShapeDetector.h:302
XShape()
Creates an invalid X-shape object.
Definition ShapeDetector.h:1159
const Vector2 & direction1() const
Return the second direction of this X-shape.
Definition ShapeDetector.h:1190
Vector2 direction1_
The direction of the second line of this X-shape.
Definition ShapeDetector.h:363
bool verifyShape(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const bool darkShape, const unsigned int minimalValueRange, const unsigned int sampleOffset=2u, const unsigned int samples=4u, const unsigned int yFramePaddingElements=0u) const
Verifies whether this X-shape is valid based on underlying image content.
Vector2 direction0_
The direction of the first line of this X-shape.
Definition ShapeDetector.h:360
const Vector2 & direction0() const
Returns the first direction of this X-shape.
Definition ShapeDetector.h:1185
This class is a collection of detectors for geometric shapes.
Definition ShapeDetector.h:37
static bool optimizeRectangleAlongEdges(const Frame &yFrame, Rectangle &rectangle, const unsigned int perpendicularSampleDistance=5u)
Optimize the location of a rectangle to its corresponding image edges Fits the line segments of a rec...
std::vector< const CV::Detector::ShapeDetector::TwoLineShape * > TwoLineShapes
Definition of a vector holding pointers to TwoLineShapes.
Definition ShapeDetector.h:153
static bool hasGreaterArea(const Rectangle &firstRectangle, const Rectangle &secondRectangle)
Returns true if the area of the first rectangle is larger than that of the second rectangle.
Definition ShapeDetector.h:1369
static LShapes filterLShapesBasedOnDirection(const LShapes &lShapes, const Vector2 alignmentDirection, const Scalar alignmentAngleThreshold=Numeric::deg2rad(15))
Filters L-shape objects based on their direction.
Definition ShapeDetector.h:1322
std::vector< TShape > TShapes
Definition of a vector holding T-shape objects.
Definition ShapeDetector.h:374
static bool areLShapesConnected(const LShape &lShapeA, const LShape &lShapeB, const Vector2 &directionA, const Vector2 &directionB, const Scalar thresholdAngleCos=Numeric::cos(Numeric::deg2rad(5)))
Checks whether two L-shapes are connected based on their orientation and edge alignment.
Definition ShapeDetector.h:1347
static Rectangles guessShapedRectanglesFromUpperCorners(const LShapes &lShapes, const Vector2 &topLeftCornerDirection, const Scalar aspectRatio, const unsigned int imageHeight, const unsigned int maxNumberOfCandidates, const Scalar thresholdCornerDirectionAngle=Numeric::deg2rad(15), const Scalar thresholdConnectedShapesAngle=Numeric::deg2rad(5), const Scalar minimalRectangleWidth=90, const Scalar maximalRectangleWidth=250, const unsigned int numCandidatePairsToGeneratePerEdge=1u, const Scalar sideEdgeRatioMultiplier=1.0)
Guesses rectangles of a specific aspect ratio from a set of upper left & right corners (provided as l...
static void determineShapes(const FiniteLines2 &horizontalFiniteLines, const FiniteLines2 &verticalFiniteLines, const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const Scalar thresholdShortDistance=Scalar(2), const Scalar thresholdLongDistance=Scalar(5), const Scalar thresholdShapeAngle=Numeric::deg2rad(20), const Scalar thresholdAngleXShape=Numeric::deg2rad(5))
Determines all possible L-shapes, T-shapes, and X-shapes which can be extracted from two sets of fini...
static void removeLinesTooCloseToBorder(FiniteLines2 &finiteLines, const unsigned int width, const unsigned int height, const Scalar thresholdDistance=Scalar(10))
Removes finite lines with end points too close to the frame border.
std::vector< LShape > LShapes
Definition of a vector holding L-shape objects.
Definition ShapeDetector.h:369
static LShapes determineLShapes(const FiniteLines2 &finiteLines, const unsigned int width, const unsigned int height, const Scalar thresholdDistance=Scalar(15), const Scalar thresholdAngle=Numeric::deg2rad(15))
Determines all possible L-shape elements which can be extracted from a set of finite lines.
std::array< Vector2, 4 > Rectangle
A rectangle defined by its four corners (counter-clockwise direction)
Definition ShapeDetector.h:394
std::array< Index32, 4 > IndexedRectangle
Definition of an array holding four indices e.g., of L-shape objects.
Definition ShapeDetector.h:384
static bool optimizeLineAlongEdge(const Frame &yFrame, const FiniteLine2 &line, Line2 &optimizedLine, const unsigned int perpendicularSampleDistance=5u, const unsigned int sampleLocations=30u, const unsigned int minimalValidSampleLocations=5u, const Scalars &sampleLocationsPercent=Scalars())
Optimize the location of a line to that of a corresponding image edge For line segments extracted fro...
std::vector< Rectangle > Rectangles
A vector of rectangles.
Definition ShapeDetector.h:399
static Rectangles detectAlignedRectangles(const Frame &yFrame, const unsigned int rectangleWidth, const Scalar aspectRatio, const Scalar aspectRatioTolerance=Scalar(0.10), const Scalar alignmentAngleTolerance=Numeric::deg2rad(35), const bool sortRectangles=true, const unsigned int lineImageBorderDistanceThreshold=5u, const unsigned int perpendicularSampleDistance=5u)
Detect approximately axis-aligned rectangles in images.
static void postAdjustShapes(const unsigned int width, const unsigned int height, LShapes &lShapes, TShapes &tShapes, XShapes &xShapes, const Scalar similarPointDistance=Scalar(1.5), const Scalar similarAngle=Numeric::deg2rad(15))
Post-processes determined shapes and merges similar shapes.
static LShapes nonMaximumSuppressionLShapes(const LShapes &lShapes, const unsigned int width, const unsigned int height, const Scalar thresholdDistance=Scalar(10), const Scalar thresholdAngle=Numeric::deg2rad(25))
Applies a non-maximum suppression of L-shapes.
static IndexedRectangles determineShapedRectangles(const FiniteLines2 &finiteLines, const LShapes &lShapes, const IndexedRectangles &rectangles, const Scalar aspectRatio, const Scalar minimalWidth=90, const Scalar maximalWidth=250, const Scalar aspectRatioTolerance=Scalar(0.1), const Scalar orthogonalAngleTolerance=Numeric::deg2rad(10))
Determines rectangles of specific size and with certain aspect ratios.
std::vector< XShape > XShapes
Definition of a vector holding X-shape objects.
Definition ShapeDetector.h:379
std::vector< IndexedRectangle > IndexedRectangles
Definition of a vector holding rectangles.
Definition ShapeDetector.h:389
static IndexedRectangles determineAlignedRectangles(const FiniteLines2 &finiteLines, const LShapes &lShapes, const Vector2 &topLeftCornerDirection, const Scalar minDistanceBetweenCorners=10, const Scalar thresholdCornerDirectionAngle=Numeric::deg2rad(15), const Scalar thresholdConnectedShapesAngle=Numeric::deg2rad(5))
Determines rectangles aligned with a specified direction.
This class implements the possibility to find local maximum in a 2D array by applying a non-maximum-s...
Definition NonMaximumSuppression.h:138
This class implements Ocean's image class.
Definition Frame.h:1969
This class implements an infinite line in 2D space.
Definition Line2.h:83
static constexpr T deg2rad(const T deg)
Converts deg to rad.
Definition Numeric.h:3241
static constexpr T pi_2()
Returns PI/2 which is equivalent to 90 degree.
Definition Numeric.h:938
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
static T cos(const T value)
Returns the cosine of a given value.
Definition Numeric.h:1588
bool isUnit(const T eps=NumericT< T >::eps()) const
Returns whether this vector is a unit vector (whether the vector has the length 1).
Definition Vector2.h:745
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition Vector2.h:549
VectorT2< T > perpendicular() const
Returns a vector perpendicular to this vectors.
Definition Vector2.h:555
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
TriangleT2< Scalar > Triangle2
Definition of the Triangle2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Triangle2.h:28
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition FiniteLine2.h:57
The namespace covering the entire Ocean framework.
Definition Accessor.h:15