8#ifndef META_OCEAN_TRACKING_PATTERN_PATTERN_TRACKER_CORE_6DOF_H
9#define META_OCEAN_TRACKING_PATTERN_PATTERN_TRACKER_CORE_6DOF_H
55 class OCEAN_TRACKING_PATTERN_EXPORT
Options
67 unsigned int maxConcurrentlyVisiblePattern_ = 1u;
70 double maxRecognitionTime_ = 0.0;
73 double recognitionCadenceWithTrackedPatterns_ = 0.5;
76 double recognitionCadenceWithoutTrackedPatterns_ = 0.0;
79 unsigned int recognitionRansacIterations_ = 50u;
82 bool noFrameToFrameTracking_ =
false;
84#ifdef OCEAN_PLATFORM_BUILD_ANDROID
87 bool downsampleInputImageOnAndroid_ =
true;
104 static constexpr unsigned int maximalDescriptorDistance_ = (
unsigned int)(Descriptor::size() * 8) * 25u / 100u;
127 FeatureMap(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int yFramePaddingElements,
const Vector2& dimension,
Worker* worker =
nullptr);
133 inline const Vectors3& objectPoints()
const;
178 Pattern(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int yFramePaddingElements,
const Vector2& dimension,
Worker* worker =
nullptr);
196 inline const Vector2& dimension()
const;
202 inline Vector3 corner0()
const;
208 inline Vector3 corner1()
const;
214 inline Vector3 corner2()
const;
220 inline Vector3 corner3()
const;
261 inline const Vectors3& objectPoints()
const;
275 inline const Vectors2& imagePoints()
const;
290 inline const Vectors2& referencePoints(
const unsigned int layer)
const;
297 inline unsigned int layers()
const;
305 inline bool hasPoseGuess(
HomogenousMatrix4& poseGuess,
const double maximalAge = 0.5);
325 inline bool isValid()
const;
336 explicit inline operator bool()
const;
399 unsigned int addPattern(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int yFramePaddingElements,
const Vector2& dimension,
Worker* worker =
nullptr);
449 inline unsigned int numberPattern()
const;
456 inline unsigned int maxConcurrentlyVisiblePattern()
const;
463 inline void setMaxConcurrentlyVisiblePattern(
const unsigned int maxConcurrentlyVisiblePattern);
500 inline double maximumDurationBetweenRecognitionAttempts()
const;
539 inline unsigned int internalNumberVisiblePattern()
const;
546 inline unsigned int internalMaxConcurrentlyVisiblePattern()
const;
589 static bool trackFrame2FrameHierarchy(
const PinholeCamera& pinholeCamera,
const CV::FramePyramid& previousFramePyramid,
const CV::FramePyramid& currentFramePyramid,
const unsigned int trackingLayer,
const HomogenousMatrix4& previousPose,
const Vectors3& previousObjectPoints,
const Vectors2& previousImagePoints,
HomogenousMatrix4& roughPose,
Worker* worker =
nullptr,
const unsigned int numberFeatures = 20u,
const Scalar maxError =
Scalar(0.9 * 0.9));
649 static OCEAN_FORCE_INLINE
unsigned int determineDescriptorDistance(
const Descriptor& descriptorA,
const Descriptor& descriptorB);
672 unsigned int patternMapIdCounter_ = 0u;
684 unsigned int lastRecognitionPatternId_ = 0u;
704 return patternPyramid_;
714 ocean_assert(isValid());
720 ocean_assert(isValid());
721 return Vector3(0, 0, dimension_.y());
726 ocean_assert(isValid());
727 return Vector3(dimension_.x(), 0, dimension_.y());
732 ocean_assert(isValid());
733 return Vector3(dimension_.x(), 0, 0);
739 result[0] =
Triangle3(corner0(), corner1(), corner2());
740 result[1] =
Triangle3(corner0(), corner2(), corner3());
747 ocean_assert(world_T_previousCamera_.isValid());
749 return triangles2(pinholeCamera, world_T_previousCamera_);
769 return world_T_previousCamera_;
774 return world_T_previousCamera_;
779 return objectPoints_;
784 return objectPoints_;
799 ocean_assert(layer < patternPyramid_.layers() && layer < pyramidReferencePoints_.size());
800 return pyramidReferencePoints_[layer];
805 return (
unsigned int)(pyramidReferencePoints_.size());
810 ocean_assert(maximalAge >= 0.0 && maximalAge <= 2.0);
812 if (world_T_guessCamera_.isValid() &&
NumericD::abs(
double(
Timestamp(
true) - poseGuessTimestamp_)) <= maximalAge)
814 poseGuess = world_T_guessCamera_;
825 *timestamp = poseGuessTimestamp_;
828 return world_T_guessCamera_;
833 world_T_guessCamera_ = pose;
834 poseGuessTimestamp_ = timestamp;
839 return patternPyramid_.
isValid();
842inline PatternTrackerCore6DOF::Pattern::operator bool()
const
875 unsigned int number = 0u;
879 if (i->second.previousPose().isValid())
902 return descriptorA.distance(descriptorB);
This class implements a frame pyramid.
Definition FramePyramid.h:37
This class implement a sub-region either defined by 2D triangles or defined by a binary mask.
Definition SubRegion.h:32
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements an occupancy array.
Definition SpatialDistribution.h:370
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1806
This class implements a recursive lock object.
Definition Lock.h:31
static T abs(const T value)
Returns the absolute value of a given value.
Definition Numeric.h:1220
bool hasDistortionParameters() const
Returns whether this camera object has specified distortion parameters.
Definition PinholeCamera.h:1293
VectorT2< T > projectToImage(const HomogenousMatrixT4< T > &world_T_camera, const VectorT3< T > &worldObjectPoint, const bool distortImagePoint, const T zoom=T(1)) const
Projects a 3D object point to the 2D image plane of the camera by a given camera pose.
Definition PinholeCamera.h:1772
This class implements a generator for random numbers.
Definition RandomGenerator.h:42
This class implements a scoped lock object for recursive lock objects.
Definition Lock.h:135
This class implements a timestamp.
Definition Timestamp.h:36
bool isValid() const
Returns whether the timestamp holds a valid time.
Definition Timestamp.h:303
Definition of a lightweight 3D feature map holding 3D object points and descriptors for all features ...
Definition PatternTrackerCore6DOF.h:110
FeatureMap(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const Vector2 &dimension, Worker *worker=nullptr)
Creates a new feature map for a planar 3D object (an image placed in the x-z plane).
Descriptors descriptors_
The descriptors of all features, one for each 3D object point location.
Definition PatternTrackerCore6DOF.h:147
const Vectors3 & objectPoints() const
Returns the 3D object points of all map features.
Definition PatternTrackerCore6DOF.h:687
Vectors3 objectPoints_
The 3D locations of all features in this map.
Definition PatternTrackerCore6DOF.h:144
FeatureMap()=default
Default constructor.
const Descriptors & descriptors() const
Returns the descriptor associated with the 3D object points of this map.
Definition PatternTrackerCore6DOF.h:692
Set of configurable parameters for the tracker.
Definition PatternTrackerCore6DOF.h:56
unsigned int maxConcurrentlyVisiblePattern_
The maximal number of patterns that can be visible concurrently, with range [1, infinity)....
Definition PatternTrackerCore6DOF.h:67
Options()
Creates a new options object.
double recognitionCadenceWithoutTrackedPatterns_
Time in seconds to wait between recognition attempts when no patterns are currently being tracked.
Definition PatternTrackerCore6DOF.h:76
double recognitionCadenceWithTrackedPatterns_
Time in seconds to wait between recognition attempts when at least one pattern is currently being tra...
Definition PatternTrackerCore6DOF.h:73
This class stores the information necessary for one tracking pattern.
Definition PatternTrackerCore6DOF.h:154
Pattern()=default
Creates a new invalid pattern object.
void setPoseGuess(const HomogenousMatrix4 &pose, const Timestamp ×tamp)
Sets a guess of the current (or next) camera pose for this pattern.
Definition PatternTrackerCore6DOF.h:831
const Vectors2 & referencePoints(const unsigned int layer) const
Returns the 2D feature points from the pyramid frame of the pattern image.
Definition PatternTrackerCore6DOF.h:797
std::vector< Vectors2 > PointLayers
Definition of a vector holding 2D feature positions.
Definition PatternTrackerCore6DOF.h:160
const HomogenousMatrix4 & previousPose() const
Returns the previous camera pose from which this tracking pattern has been seen.
Definition PatternTrackerCore6DOF.h:767
Vector3 corner2() const
Returns the third 3D corner position of the tracking pattern in the tracker coordinate system.
Definition PatternTrackerCore6DOF.h:724
void reset()
Resets the internal recognition states of this pattern while the actual feature map is untouched.
const Vector2 & dimension() const
Returns the dimension of the tracking object defined in the tracker coordinate system.
Definition PatternTrackerCore6DOF.h:707
const Vectors3 & objectPoints() const
Returns the 3D object points of this pattern which have been used in the previous (or current) tracki...
Definition PatternTrackerCore6DOF.h:777
Pattern(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const Vector2 &dimension, Worker *worker=nullptr)
Creates a new pattern object by a given frame and pattern dimension.
Triangles2 triangles2(const PinholeCamera &pinholeCamera) const
Returns the two projected 2D triangles specifying the tracking pattern in the camera frame as seen wi...
Definition PatternTrackerCore6DOF.h:745
Timestamp poseGuessTimestamp_
The timestamp of the rough camera pose.
Definition PatternTrackerCore6DOF.h:365
CV::FramePyramid patternPyramid_
The frame pyramid of the image specifying the pattern.
Definition PatternTrackerCore6DOF.h:344
Vectors3 objectPoints_
The 3D object points which have been used in the previous (or current) tracking iteration.
Definition PatternTrackerCore6DOF.h:353
Vectors2 imagePoints_
The 2D image points which have been used in the previous (or current) tracking iteration.
Definition PatternTrackerCore6DOF.h:356
Triangles3 triangles3() const
Returns the two 3D triangles covering the tracking area of this tracking pattern.
Definition PatternTrackerCore6DOF.h:736
const CV::FramePyramid & pyramid() const
Returns the frame pyramid of the image defining the tracking pattern.
Definition PatternTrackerCore6DOF.h:702
unsigned int layers() const
Returns the number of pyramid layers of the pattern image.
Definition PatternTrackerCore6DOF.h:803
Vector3 corner0() const
Returns the first 3D corner position of the tracking pattern in the tracker coordinate system.
Definition PatternTrackerCore6DOF.h:712
bool isValid() const
Returns whether this tracking pattern object is valid.
Definition PatternTrackerCore6DOF.h:837
Vector3 corner1() const
Returns the second 3D corner position of the tracking pattern in the tracker coordinate system.
Definition PatternTrackerCore6DOF.h:718
Vector3 corner3() const
Returns the fourth 3D corner position of the tracking pattern in the tracker coordinate system.
Definition PatternTrackerCore6DOF.h:730
const Vectors2 & imagePoints() const
Returns the 2D image points of this pattern which have been used in the previous (or current) trackin...
Definition PatternTrackerCore6DOF.h:787
const FeatureMap & featureMap() const
Returns the feature map of this pattern.
Definition PatternTrackerCore6DOF.h:697
PointLayers pyramidReferencePoints_
The point pyramid of the pattern image storing reference feature points for individual pattern resolu...
Definition PatternTrackerCore6DOF.h:359
FeatureMap featureMap_
The feature map of this pattern.
Definition PatternTrackerCore6DOF.h:341
bool hasPoseGuess(HomogenousMatrix4 &poseGuess, const double maximalAge=0.5)
Returns whether this pattern holds a valid/useful rough guess of the camera pose.
Definition PatternTrackerCore6DOF.h:808
const HomogenousMatrix4 & poseGuess(Timestamp *timestamp=nullptr)
Returns a guess of the current camera pose for this pattern.
Definition PatternTrackerCore6DOF.h:821
This class implements the core of the 6DOF feature tracker for planar patterns.
Definition PatternTrackerCore6DOF.h:49
bool determinePosesWithoutKnowledge(const PinholeCamera &pinholeCamera, const Frame &yFrame, const CV::FramePyramid ¤tFramePyramid, const Quaternion &previousCamera_R_camera=Quaternion(false), Worker *worker=nullptr)
Determines the 6DOF poses for the registered patterns without any a-priori information.
~PatternTrackerCore6DOF()
Destructs a feature tracker object.
bool removePatterns()
Removes all patterns from this tracker.
CV::Detector::FREAKDescriptor32 Descriptor
Definition of the descriptor to be used.
Definition PatternTrackerCore6DOF.h:96
static bool optimizePoseByRectification(const PinholeCamera &pinholeCamera, const CV::FramePyramid ¤tFramePyramid, const HomogenousMatrix4 &roughPose, const Pattern &pattern, HomogenousMatrix4 &optimizedPose, Worker *worker=nullptr, Geometry::SpatialDistribution::OccupancyArray *occlusionArray=nullptr)
Optimizes a given camera pose by rectification of the current camera frame so that it matches with th...
Timestamp lastRecognitionAttemptTimestamp_
The last timestamp at which we started an attempt to recognize a new pattern (this timestamp is prior...
Definition PatternTrackerCore6DOF.h:681
Options options_
Set of options for this tracker.
Definition PatternTrackerCore6DOF.h:654
CV::FramePyramid currentFramePyramid_
Frame pyramid of the current tracking frame.
Definition PatternTrackerCore6DOF.h:657
Timestamp timestampPreviousFrame_
The timestamp of the previous frame.
Definition PatternTrackerCore6DOF.h:678
unsigned int addPattern(const uint8_t *yFrame, const unsigned int width, const unsigned int height, const unsigned int yFramePaddingElements, const Vector2 &dimension, Worker *worker=nullptr)
Adds a new 2D tracking pattern (an image) to the tracker.
void setMaxConcurrentlyVisiblePattern(const unsigned int maxConcurrentlyVisiblePattern)
Sets the maximal number of pattern that can be tracked concurrently within one frame.
Definition PatternTrackerCore6DOF.h:861
unsigned int addPattern(const std::string &filename, const Vector2 &dimension, Worker *worker=nullptr)
Adds a new 2D tracking pattern (an image) to the tracker.
bool recentFeatureCorrespondences(const unsigned int patternId, Vectors2 &imagePoints, Vectors3 &objectPoints, HomogenousMatrix4 *pattern_T_camera=nullptr) const
Returns the latest 2D/3D correspondences for a pattern which has been used to determine the camera po...
std::map< unsigned int, Pattern > PatternMap
Definition of a map holding pattern objects.
Definition PatternTrackerCore6DOF.h:371
CV::Detector::FREAKDescriptors32 Descriptors
Definition of the descriptors to be used.
Definition PatternTrackerCore6DOF.h:101
RandomGenerator randomGenerator_
Random generator object.
Definition PatternTrackerCore6DOF.h:669
static OCEAN_FORCE_INLINE unsigned int determineDescriptorDistance(const Descriptor &descriptorA, const Descriptor &descriptorB)
Simple helper function to determine the distance between two feature descriptors.
Definition PatternTrackerCore6DOF.h:900
unsigned int internalNumberVisiblePattern() const
Counts the number of currently visible pattern.
Definition PatternTrackerCore6DOF.h:873
CV::FramePyramid previousFramePyramid_
Frame pyramid of the previous tracking frame.
Definition PatternTrackerCore6DOF.h:660
static bool detectAndDescribeFeatures(const SharedAnyCamera &camera, const Frame &yFrame, Vectors2 &imagePoints, Descriptors &imagePointDescriptors, const unsigned int harrisCornerThreshold=20u, Worker *worker=nullptr)
Determines and describes feature points in an image.
static CV::SubRegion triangles2subRegion(const Triangles2 &triangles, const unsigned int backupWidth, const unsigned int backupHeight)
Returns a sub region based on a set of given 2D triangles.
void reset()
Resets the tracker's states but keeps all registered pattern.
static bool convertPoseForCamera(const PinholeCamera &newCamera, const PinholeCamera &referenceCamera, const HomogenousMatrix4 &referencePose, HomogenousMatrix4 &newPose)
Converts a known camera pose determined by this pattern tracker to a corresponding camera pose based ...
static bool determinePoseWithDriftErrors(const PinholeCamera &pinholeCamera, const CV::FramePyramid &previousFramePyramid, const CV::FramePyramid ¤tFramePyramid, Pattern &pattern, const Quaternion &previousCamera_R_camera=Quaternion(false), Worker *worker=nullptr)
Determines the camera pose for extreme camera motion for a given pattern for which a pose guess is kn...
bool determinePoses(const bool allowRecognition, const Frame &yFrame, const PinholeCamera &pinholeCamera, const Quaternion &previousCamera_R_camera=Quaternion(false), Worker *worker=nullptr)
Determines the 6DOF tracking for a given frame.
bool removePattern(const unsigned int patternId)
Removes a pattern from this tracker.
Lock lock_
Tracker lock object.
Definition PatternTrackerCore6DOF.h:675
unsigned int numberPattern() const
Returns the number of registered/added pattern.
Definition PatternTrackerCore6DOF.h:847
unsigned int internalMaxConcurrentlyVisiblePattern() const
Returns the maximal number of pattern that can be tracked concurrently within one frame.
Definition PatternTrackerCore6DOF.h:888
bool determinePoses(const uint8_t *yFrame, const PinholeCamera &pinholeCamera, const unsigned int yFramePaddingElements, const bool frameIsUndistorted, const Timestamp ×tamp, VisualTracker::TransformationSamples &transformations, const Quaternion &world_R_camera=Quaternion(false), Worker *worker=nullptr)
Executes the 6DOF tracking for a given frame.
static bool trackFrame2FrameHierarchy(const PinholeCamera &pinholeCamera, const CV::FramePyramid &previousFramePyramid, const CV::FramePyramid ¤tFramePyramid, const unsigned int trackingLayer, const HomogenousMatrix4 &previousPose, const Vectors3 &previousObjectPoints, const Vectors2 &previousImagePoints, HomogenousMatrix4 &roughPose, Worker *worker=nullptr, const unsigned int numberFeatures=20u, const Scalar maxError=Scalar(0.9 *0.9))
Tracks a set of 2D/3D points correspondences from the previous frame to the current frame (in a speci...
unsigned int maxConcurrentlyVisiblePattern() const
Returns the maximal number of pattern that can be tracked concurrently within one frame.
Definition PatternTrackerCore6DOF.h:854
PatternMap patternMap_
The map holding all registered pattern object.
Definition PatternTrackerCore6DOF.h:663
double maximumDurationBetweenRecognitionAttempts() const
Computes the maximum allowed time between recognition attempts, which may depend on whether or not an...
Definition PatternTrackerCore6DOF.h:868
bool determinePosesWithDownsampledResolution(const bool allowRecognition, const Frame &yFrame, const PinholeCamera &pinholeCamera, const Quaternion &previousCamera_R_camera=Quaternion(false), Worker *worker=nullptr)
Determines the 6DOF tracking for a given frame which has been downsampled.
PatternTrackerCore6DOF(const Options &options=Options())
Creates a new feature tracker object.
static bool determinePoseWithPreviousCorrespondences(const PinholeCamera &pinholeCamera, const CV::FramePyramid &previousFramePyramid, const CV::FramePyramid ¤tFramePyramid, Pattern &pattern, const Quaternion &previousCamera_R_camera=Quaternion(false), Worker *worker=nullptr)
Determine the camera pose for the current camera frame and for a given pattern by application of 2D/3...
static bool trackFrame2Frame(const PinholeCamera &pinholeCamera, const CV::FramePyramid &previousFramePyramid, const CV::FramePyramid ¤tFramePyramid, const HomogenousMatrix4 &previousPose, Vectors3 &previousObjectPoints, Vectors2 &previousImagePoints, Vectors2 ¤tImagePoints, HomogenousMatrix4 ¤tPose, const HomogenousMatrix4 &roughCurrentPose=HomogenousMatrix4(false), Worker *worker=nullptr)
Tracks a set of 2D/3D points correspondences from the previous frame to the current frame.
std::vector< TransformationSample > TransformationSamples
Definition of a vector holding a transformation sample object.
Definition tracking/VisualTracker.h:98
This class implements a 3D triangle.
Definition Triangle3.h:80
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
TriangleT3< Scalar > Triangle3
Definition of the Triangle3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Triangle3.h:28
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::vector< Triangle2 > Triangles2
Definition of a vector holding 2D triangles.
Definition Triangle2.h:57
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:60
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition Triangle3.h:57
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< FREAKDescriptor32 > FREAKDescriptors32
Vector of 32-bytes long FREAK descriptors.
Definition FREAKDescriptor.h:69
FREAKDescriptorT< 32 > FREAKDescriptor32
Typedef for the 32-bytes long FREAK descriptor.
Definition FREAKDescriptor.h:66
The namespace covering the entire Ocean framework.
Definition Accessor.h:15