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 typedef std::vector<const CV::Detector::ShapeDetector::TwoLineShape*>
TwoLineShapes;
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);
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>
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);
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);
1018 shapeType_(ST_INVALID),
1019 finiteLineIndex0_((unsigned int)(-1)),
1020 finiteLineIndex1_((unsigned int)(-1)),
1027 shapeType_(shapeType),
1028 finiteLineIndex0_((unsigned int)(-1)),
1029 finiteLineIndex1_((unsigned int)(-1)),
1030 position_(position),
1039 shapeType_(shapeType),
1040 finiteLineIndex0_(finiteLineIndex0),
1041 finiteLineIndex1_(finiteLineIndex1),
1042 position_(position),
1057 return finiteLineIndex0_;
1062 return finiteLineIndex1_;
1067 ocean_assert(index <= 1u);
1068 return index == 0u ? finiteLineIndex0() : finiteLineIndex1();
1078 position_ = position;
1094 edgeLeft_(edgeLeft),
1095 edgeRight_(edgeRight),
1096 direction_(direction)
1108 TwoLineShape(ST_SHAPE_L, finiteLineIndex0, finiteLineIndex1, position, score),
1109 edgeLeft_(edgeLeft),
1110 edgeRight_(edgeRight),
1111 direction_(direction)
1145 direction_(direction)
1151 TwoLineShape(ST_SHAPE_T, finiteLineIndex0, finiteLineIndex1, position, score),
1152 direction_(direction)
1170 direction0_(direction0),
1171 direction1_(direction1)
1179 TwoLineShape(ST_SHAPE_X, finiteLineIndex0, finiteLineIndex1, position, score),
1180 direction0_(direction0),
1181 direction1_(direction1)
1200 ocean_assert(width >= shapeWidth_);
1201 return width - shapeWidth_ + 1u;
1206 ocean_assert(height >= shapeBandSize_ * 2u + shapeStepSize_);
1207 return height - (shapeBandSize_ * 2u + shapeStepSize_) + 1u;
1212 ocean_assert(width >= shapeBandSize_ * 2u + shapeStepSize_);
1213 return width - (shapeBandSize_ * 2u + shapeStepSize_) + 1u;
1218 ocean_assert(height >= shapeHeight_ - shapeStepSize_);
1219 return height - (shapeHeight_ - shapeStepSize_) + 1u;
1224 return int(shapeWidth_2_);
1229 return int(shapeBandSize_ + shapeStepSize_2_);
1234 return int(shapeBandSize_ + shapeStepSize_2_);
1239 return -int(shapeStepSize_2_ + 1u);
1246 return frameX_T_topDownHorizontalResponseX() > frameX_T_topDownVerticalResponseX() ? frameX_T_topDownHorizontalResponseX() : frameX_T_topDownVerticalResponseX();
1253 return frameY_T_topDownHorizontalResponseY() > frameY_T_topDownVerticalResponseY() ? frameY_T_topDownHorizontalResponseY() : frameY_T_topDownVerticalResponseY();
1258 return int(shapeWidth_2_);
1263 return int(shapeBandSize_ + shapeStepSize_2_);
1268 return int(shapeBandSize_ + shapeStepSize_2_);
1273 return int(shapeHeight_ - shapeStepSize_2_ - 1u);
1280 return frameX_T_bottomUpHorizontalResponseX() > frameX_T_bottomUpVerticalResponseX() ? frameX_T_bottomUpHorizontalResponseX() : frameX_T_bottomUpVerticalResponseX();
1287 return frameY_T_bottomUpHorizontalResponseY() > frameY_T_bottomUpVerticalResponseY() ? frameY_T_bottomUpHorizontalResponseY() : frameY_T_bottomUpVerticalResponseY();
1294 return horizontalResponse < 0.0f && verticalResponse < 0.0f;
1298 return horizontalResponse > 0.0f && verticalResponse > 0.0f;
1302 ocean_assert(sign == 0);
1303 return (horizontalResponse < 0.0f && verticalResponse < 0.0f) || (horizontalResponse > 0.0f && verticalResponse > 0.0f);
1311 return horizontalResponse < 0 && verticalResponse < 0;
1315 return horizontalResponse > 0 && verticalResponse > 0;
1319 ocean_assert(sign == 0);
1320 return (horizontalResponse < 0 && verticalResponse < 0) || (horizontalResponse > 0 && verticalResponse > 0);
1324 template <
bool tAllowPerpendicularDirections>
1327 ocean_assert(alignmentDirection.
isUnit());
1328 ocean_assert(alignmentAngleThreshold >= 0 && alignmentAngleThreshold <=
Numeric::pi_2());
1331 ocean_assert(perpendicularAlignmentDirection.
isUnit());
1336 filteredLShapes.reserve(lShapes.size());
1338 for (
const LShape& lShape : lShapes)
1340 if (
Numeric::abs(lShape.direction() * alignmentDirection) >= alginmentAngleThresholdCos
1341 || (tAllowPerpendicularDirections &&
Numeric::abs(lShape.direction() * perpendicularAlignmentDirection) >= alginmentAngleThresholdCos))
1343 filteredLShapes.push_back(lShape);
1347 return filteredLShapes;
1353 ocean_assert(directionA.
isUnit() && directionB.
isUnit());
1357 if (directionA * direction < thresholdAngleCos)
1363 if (-(directionB * direction) < thresholdAngleCos)
1374 ocean_assert(
Triangle2(firstRectangle[0], firstRectangle[1], firstRectangle[2]).isValid() &&
Triangle2(firstRectangle[2], firstRectangle[3], firstRectangle[0]).isValid());
1375 ocean_assert(
Triangle2(secondRectangle[0], secondRectangle[1], secondRectangle[2]).isValid() &&
Triangle2(secondRectangle[2], secondRectangle[3], secondRectangle[0]).isValid());
1377 const Scalar areaFirstRectangle =
Triangle2(firstRectangle[0], firstRectangle[1], firstRectangle[2]).area2() +
Triangle2(firstRectangle[2], firstRectangle[3], firstRectangle[0]).area2();
1378 const Scalar areaSecondRectangle =
Triangle2(secondRectangle[0], secondRectangle[1], secondRectangle[2]).area2() +
Triangle2(secondRectangle[2], secondRectangle[3], secondRectangle[0]).area2();
1380 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:1122
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:1086
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:1132
const Vector2 & edgeRight() const
Returns the right edge of this L-shape.
Definition: ShapeDetector.h:1127
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 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:1249
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:1266
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:1232
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:1222
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:1271
static constexpr int frameY_T_bottomUpHorizontalResponseY()
Returns the translation offset in y-direction between the horizontal bottom-up response location and ...
Definition: ShapeDetector.h:1261
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::NonMaximumSuppression< uint32_t > &nonMaximumSuppressionTopDown, CV::NonMaximumSuppression< 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 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:1290
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::NonMaximumSuppression< float > &nonMaximumSuppression, Frame *responseFrame=nullptr)
Determines the floating-point T-shape responses for the top-down direction.
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:1237
static unsigned int determineVerticalResponseWidth(const unsigned int width)
Returns the width of the vertical response frame.
Definition: ShapeDetector.h:1210
static unsigned int determineHorizontalResponseHeight(const unsigned int height)
Returns the height of the horizontal response frame.
Definition: ShapeDetector.h:1204
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:1283
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:1276
static unsigned int determineVerticalResponseHeight(const unsigned int height)
Returns the height of the vertical response frame.
Definition: ShapeDetector.h:1216
static unsigned int determineHorizontalResponseWidth(const unsigned int width)
Returns the width of the horizontal response frame.
Definition: ShapeDetector.h:1198
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:1227
static constexpr int frameX_T_bottomUpHorizontalResponseX()
Returns the translation offset in x-direction between the horizontal bottom-up response location and ...
Definition: ShapeDetector.h:1256
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:1242
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.
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::NonMaximumSuppression< float > &nonMaximumSuppression, Frame *responseFrame=nullptr)
Determines the floating-point T-shape responses for the bottom-up direction.
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:1157
TShape()
Creates an invalid T-shape object.
Definition: ShapeDetector.h:1137
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:1076
TwoLineShape()
Creates an invalid shape.
Definition: ShapeDetector.h:1017
ShapeType type() const
Returns the type of the shape.
Definition: ShapeDetector.h:1050
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:1065
unsigned int finiteLineIndex1() const
Returns the index of the second finite line.
Definition: ShapeDetector.h:1060
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:1081
unsigned int finiteLineIndex0() const
Returns the index of the first finite line.
Definition: ShapeDetector.h:1055
const Vector2 & position() const
Returns the position of this shape.
Definition: ShapeDetector.h:1071
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:1162
const Vector2 & direction1() const
Return the second direction of this X-shape.
Definition: ShapeDetector.h:1193
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:1188
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::array< Vector2, 4 > Rectangle
A rectangle defined by its four corners (counter-clockwise direction)
Definition: ShapeDetector.h:394
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:1372
std::vector< LShape > LShapes
Definition of a vector holding L-shape objects.
Definition: ShapeDetector.h:369
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:1325
std::vector< const CV::Detector::ShapeDetector::TwoLineShape * > TwoLineShapes
Definition of a vector holding pointers to TwoLineShapes.
Definition: ShapeDetector.h:153
std::array< Index32, 4 > IndexedRectangle
Definition of an array holding four indices e.g., of L-shape objects.
Definition: ShapeDetector.h:384
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:1350
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...
std::vector< Rectangle > Rectangles
A vector of rectangles.
Definition: ShapeDetector.h:399
std::vector< TShape > TShapes
Definition of a vector holding T-shape objects.
Definition: ShapeDetector.h:374
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...
std::vector< XShape > XShapes
Definition of a vector holding X-shape objects.
Definition: ShapeDetector.h:379
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.
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::vector< IndexedRectangle > IndexedRectangles
Definition of a vector holding rectangles.
Definition: ShapeDetector.h:389
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...
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.
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:41
This class implements Ocean's image class.
Definition: Frame.h:1792
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:3232
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:1584
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:740
T cross(const VectorT2< T > &vector) const
Returns the cross product of two 2D vectors.
Definition: Vector2.h:544
VectorT2< T > perpendicular() const
Returns a vector perpendicular to this vectors.
Definition: Vector2.h:550
float Scalar
Definition of a scalar type.
Definition: Math.h:128
TriangleT2< Scalar > Triangle2
Definition of the Triangle2 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition: Triangle2.h:21
std::vector< FiniteLine2 > FiniteLines2
Definition of a vector holding FiniteLine2 objects.
Definition: FiniteLine2.h:57
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition: Math.h:144
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15