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
84#ifdef OCEAN_PLATFORM_BUILD_ANDROID
127 FeatureMap(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int yFramePaddingElements,
const Vector2& dimension,
Worker* worker =
nullptr);
178 Pattern(
const uint8_t* yFrame,
const unsigned int width,
const unsigned int height,
const unsigned int yFramePaddingElements,
const Vector2&
dimension,
Worker* worker =
nullptr);
297 inline unsigned int layers()
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);
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));
810 ocean_assert(maximalAge >= 0.0 && maximalAge <= 2.0);
842inline PatternTrackerCore6DOF::Pattern::operator bool()
const
858 return options_.maxConcurrentlyVisiblePattern_;
875 unsigned int number = 0u;
877 for (
const PatternMap::value_type& pair :
patternMap_)
879 if (pair.second.previousPose().isValid())
890 if (
options_.maxConcurrentlyVisiblePattern_ == 0u)
902 return descriptorA.
distance(descriptorB);
OCEAN_FORCE_INLINE unsigned int distance(const FREAKDescriptorT< tSize > &descriptor) const
Returns the distance between this descriptor and a second descriptor.
Definition FREAKDescriptor.h:587
static constexpr size_t size()
This class implements a frame pyramid.
Definition FramePyramid.h:46
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:1969
This class implements an occupancy array.
Definition SpatialDistribution.h:414
bool isValid() const
Returns whether this matrix is a valid homogeneous transformation.
Definition HomogenousMatrix4.h:1800
This class implements a recursive lock object.
Definition Lock.h:31
static double abs(const double value)
bool hasDistortionParameters() const
Returns whether this camera object has specified distortion parameters.
Definition PinholeCamera.h:1445
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:1962
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:147
This class implements a timestamp.
Definition Timestamp.h:64
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 recognitionRansacIterations_
The number of iterations to run RANSAC when attempting to verify a newly recognized target.
Definition PatternTrackerCore6DOF.h:79
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 maxRecognitionTime_
The maximal time used for pattern recognition for each frame in seconds, with range (0,...
Definition PatternTrackerCore6DOF.h:70
double recognitionCadenceWithoutTrackedPatterns_
Time in seconds to wait between recognition attempts when no patterns are currently being tracked.
Definition PatternTrackerCore6DOF.h:76
bool downsampleInputImageOnAndroid_
True, to apply a downsampling on Android devices to improve performance on low end devices.
Definition PatternTrackerCore6DOF.h:87
double recognitionCadenceWithTrackedPatterns_
Time in seconds to wait between recognition attempts when at least one pattern is currently being tra...
Definition PatternTrackerCore6DOF.h:73
bool noFrameToFrameTracking_
True, to skip frame-to-frame tracking and to apply a full re-detection for every frame.
Definition PatternTrackerCore6DOF.h:82
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
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
HomogenousMatrix4 world_T_guessCamera_
A rough guess of the camera pose for this pattern, if any.
Definition PatternTrackerCore6DOF.h:362
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
Vector2 dimension_
The dimension of the tracking pattern defined in the tracker coordinate system as (x-axis,...
Definition PatternTrackerCore6DOF.h:347
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
HomogenousMatrix4 world_T_previousCamera_
The previous camera pose for this tacking pattern, if any.
Definition PatternTrackerCore6DOF.h:350
std::vector< Vectors2 > PointLayers
Definition of a vector holding 2D feature positions.
Definition PatternTrackerCore6DOF.h:160
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
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.
std::map< unsigned int, Pattern > PatternMap
Definition of a map holding pattern objects.
Definition PatternTrackerCore6DOF.h:371
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...
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 constexpr unsigned int maximalDescriptorDistance_
The maximal distance between two descriptors to be considered as similar.
Definition PatternTrackerCore6DOF.h:104
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...
unsigned int patternMapIdCounter_
A counter providing unique pattern ids.
Definition PatternTrackerCore6DOF.h:672
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.
unsigned int lastRecognitionPatternId_
The id of the pattern that has been tried to recognized last.
Definition PatternTrackerCore6DOF.h:684
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
Quaternion world_R_previousCamera_
Optional absolute orientation for the previous camera frame (as provided from outside this tracker,...
Definition PatternTrackerCore6DOF.h:666
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 worker able to distribute function calls over different threads.
Definition Worker.h:33
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
QuaternionT< Scalar > Quaternion
Definition of the Quaternion object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sin...
Definition Quaternion.h:40
PinholeCameraT< Scalar > PinholeCamera
Definition of an pinhole camera object with Scalar precision.
Definition PinholeCamera.h:39
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition HomogenousMatrix4.h:44
VectorT2< Scalar > Vector2
Definition of a 2D vector.
Definition Vector2.h:28
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
TriangleT3< Scalar > Triangle3
Definition of the Triangle3 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION either with sing...
Definition Triangle3.h:28
VectorT3< Scalar > Vector3
Definition of a 3D vector.
Definition Vector3.h:29
std::vector< Triangle2 > Triangles2
Definition of a vector holding 2D triangles.
Definition Triangle2.h:57
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< Triangle3 > Triangles3
Definition of a vector holding 3D triangles.
Definition Triangle3.h:57
float Scalar
Definition of a scalar type.
Definition Math.h:129
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
Namespace of the Pattern Tracker library.
Definition tracking/pattern/Pattern.h:20
Namespace of the Tracker library.
The namespace covering the entire Ocean framework.
Definition Accessor.h:15