8 #ifndef META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_MATCHING_H
9 #define META_OCEAN_TRACKING_MAPBUILDING_UNIFIED_MATCHING_H
95 template <
typename TDistance>
283 template <typename TImagePointDescriptor, typename TObjectPointDescriptor, typename TDistance = typename UnifiedDescriptor::DistanceTyper<TImagePointDescriptor>::Type>
300 template <
typename TDescriptor>
370 template <u
int16_t tElements>
380 template <typename TImagePointDescriptor, typename TObjectPointVocabularyDescriptor, typename TDistance = typename UnifiedDescriptor::DistanceTyper<TImagePointDescriptor>::Type>
470 template <u
int16_t tElements>
495 template <
typename TDescriptor>
640 binaryDistance_(binaryDistance)
646 floatDistance_(floatDistance)
652 binaryDistance_(binaryDistance),
653 floatDistance_(floatDistance)
660 ocean_assert(binaryDistance_ != (
unsigned int)(-1));
661 return binaryDistance_;
666 ocean_assert(floatDistance_ >= 0.0f);
667 return floatDistance_;
670 template <
typename TDistance>
673 if constexpr (std::is_floating_point<TDistance>::value)
675 return TDistance(floatDistance_);
681 return TDistance(binaryDistance_);
687 return binaryDistance_ != (
unsigned int)(-1) || (floatDistance_ >= 0.0f && floatDistance_ <= 1.0f);
698 imagePoints_(imagePoints),
699 numberImagePoints_(numberImagePoints),
700 objectPoints_(objectPoints),
701 numberObjectPoints_(numberObjectPoints)
713 objectPointOctree_(objectPointOctree),
714 objectPointIds_(objectPointIds)
720 UnifiedMatching(imagePoints, numberImagePoints, objectPoints, numberObjectPoints),
721 objectPointOctree_(objectPointOctree),
722 objectPointIds_(objectPointIds)
729 objectPointIndices_(objectPointIndices)
735 UnifiedMatching(imagePoints, numberImagePoints, objectPoints, numberObjectPoints),
736 objectPointIndices_(objectPointIndices)
741 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intDescriptor,
typename TDistance>
744 objectPointDescriptorMap_(objectPointDescriptorMap)
749 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intDescriptor,
typename TDistance>
751 UnifiedGuidedMatching(imagePoints, numberImagePoints, objectPoints, numberObjectPoints, objectPointOctree, objectPointIds),
752 imagePointDescriptors_(imagePointDescriptors),
753 objectPointDescriptorMap_(objectPointDescriptorMap)
758 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intDescriptor,
typename TDistance>
761 imagePoints_ = imagePoints;
762 imagePointDescriptors_ = imagePointDescriptors;
763 numberImagePoints_ = numberImagePoints;
766 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intDescriptor,
typename TDistance>
769 imagePoints_ =
nullptr;
770 imagePointDescriptors_ =
nullptr;
771 numberImagePoints_ = 0;
774 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intDescriptor,
typename TDistance>
777 PoseEstimationT::determineGuidedMatchings<ImagePointDescriptor, ObjectPointDescriptor, DescriptorDistance, UnifiedDescriptorT<TImagePointDescriptor>::determineDistance>(anyCamera, world_T_camera, imagePoints_, imagePointDescriptors_, numberImagePoints_, objectPoints_, objectPointOctree_, objectPointIds_, objectPointDescriptorMap_, matchedImagePoints, matchedObjectPoints, maximalDescriptorDistance.
distance<TDistance>(), matchedImagePointIndices, matchedObjectPointIds, worker);
780 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intVocabularyDescriptor,
typename TDistance>
783 objectPointVocabularyDescriptors_(objectPointVocabularyDescriptors),
784 forestObjectPointDescriptors_(forestObjectPointDescriptors)
789 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intVocabularyDescriptor,
typename TDistance>
792 imagePointDescriptors_(imagePointDescriptors),
793 objectPointVocabularyDescriptors_(objectPointVocabularyDescriptors),
794 forestObjectPointDescriptors_(forestObjectPointDescriptors)
799 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intVocabularyDescriptor,
typename TDistance>
802 imagePoints_ = imagePoints;
803 imagePointDescriptors_ = imagePointDescriptors;
804 numberImagePoints_ = numberImagePoints;
807 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intVocabularyDescriptor,
typename TDistance>
810 imagePoints_ =
nullptr;
811 imagePointDescriptors_ =
nullptr;
812 numberImagePoints_ = 0;
815 template <
typename TImagePo
intDescriptor,
typename TObjectPo
intVocabularyDescriptor,
typename TDistance>
818 if (imagePoints_ ==
nullptr || imagePointDescriptors_ ==
nullptr || numberImagePoints_ == 0)
825 if constexpr (std::is_same<TImagePointDescriptor, DescriptorHandling::FreakMultiDescriptor256>::value)
827 forestObjectPointDescriptors_.template matchMultiDescriptors<ImagePointDescriptor, DescriptorHandling::multiDescriptorFunction, VocabularyTree::MM_ALL_GOOD_LEAFS_2>(objectPointVocabularyDescriptors_, imagePointDescriptors_, numberImagePoints_, maximalDescriptorDistance.
distance<TDistance>(), matches, worker);
831 forestObjectPointDescriptors_.template matchDescriptors<VocabularyTree::MM_ALL_GOOD_LEAFS_2>(objectPointVocabularyDescriptors_, imagePointDescriptors_, numberImagePoints_, maximalDescriptorDistance.
distance<TDistance>(), matches, worker);
834 if (matches.size() <
size_t(minimalNumberCorrespondences))
839 ocean_assert(matchedImagePoints.empty());
840 ocean_assert(matchedObjectPoints.empty());
842 matchedImagePoints.clear();
843 matchedObjectPoints.clear();
847 matchedImagePoints.emplace_back(imagePoints_[match.queryDescriptorIndex()]);
848 matchedObjectPoints.emplace_back(objectPoints_[objectPointIndices_[match.candidateDescriptorIndex()]]);
856 objectPointDescriptorMap_(objectPointDescriptorMap)
862 UnifiedGuidedMatching(imagePoints, numberImagePoints, objectPoints, numberObjectPoints, objectPointOctree, objectPointIds),
863 imagePointDescriptorGroups_(imagePointDescriptorGroups),
864 objectPointDescriptorMap_(objectPointDescriptorMap)
885 objectPointDescriptors_(objectPointDescriptors),
886 forestObjectPointDescriptors_(forestObjectPointDescriptors)
893 imagePointDescriptorGroups_(imagePointDescriptorGroups),
894 objectPointDescriptors_(objectPointDescriptors),
895 forestObjectPointDescriptors_(forestObjectPointDescriptors)
This class implements the abstract base class for all AnyCamera objects.
Definition: AnyCamera.h:130
This class provides basic numeric functionalities.
Definition: Numeric.h:57
std::array< float, tNumberElements > FloatDescriptor
Definition of a float descriptor.
Definition: UnifiedDescriptor.h:140
std::vector< FloatDescriptor< tNumberElements > > FloatDescriptors
Definition of a vector holding float descriptors.
Definition: UnifiedDescriptor.h:147
ByteDescriptor< tNumberBits/8u > BinaryDescriptor
Definition of a binary descriptor.
Definition: UnifiedDescriptor.h:126
This class implements the guided matching object for groups of FREAK Multi features with 32 bytes or ...
Definition: UnifiedMatching.h:478
UnifiedGuidedMatchingFreakMultiDescriptor256Group(const Vector3 *objectPoints, const size_t numberObjectPoints, const Geometry::Octree &objectPointOctree, const Index32 *objectPointIds, const UnorderedDescriptorMap< ObjectPointDescriptor > &objectPointDescriptorMap)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:854
CV::Detector::FREAKDescriptor32 ImagePointDescriptor
Definition of the descriptor for 2D image points.
Definition: UnifiedMatching.h:484
void determineGuidedMatchings(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, const DistanceValue &maximalDescriptorDistance, Indices32 *matchedImagePointIndices=nullptr, Indices32 *matchedObjectPointIds=nullptr, Worker *worker=nullptr) const override
Determines the guided matching between 2D and 3D feature points.
std::unordered_map< Index32, TDescriptor > UnorderedDescriptorMap
Definition of an unordered map mapping object point ids to descriptors.
Definition: UnifiedMatching.h:496
CV::Detector::FREAKDescriptors32 ObjectPointDescriptor
Definition of the descriptor for 3D object points (several descriptors per point possible).
Definition: UnifiedMatching.h:490
const ImagePointDescriptorGroup * imagePointDescriptorGroups_
The groups of descriptors for the image points, one for each image point.
Definition: UnifiedMatching.h:548
void updateImagePoints(const Vector2 *imagePoints, const ImagePointDescriptorGroup *imagePointDescriptorGroups, const size_t numberImagePoints)
Updates the 2D image points e.g., to allow matching for a new camera frame.
Definition: UnifiedMatching.h:869
const CV::Detector::FREAKDescriptors32 * ImagePointDescriptorGroup
Definition of the groups of descriptors for 2D image points.
Definition: UnifiedMatching.h:487
const UnorderedDescriptorMap< ObjectPointDescriptor > & objectPointDescriptorMap_
The map mapping object point ids to their corresponding descriptors.
Definition: UnifiedMatching.h:551
void clearImagePoints()
Removes the image points from this object.
Definition: UnifiedMatching.h:876
unsigned int DescriptorDistance
Definition of the distance for the binary descriptor.
Definition: UnifiedMatching.h:481
This class implements the base class for all guided matching objects.
Definition: UnifiedMatching.h:166
const Geometry::Octree & objectPointOctree_
The octree holding all 3D object points.
Definition: UnifiedMatching.h:209
const Index32 * objectPointIds_
The ids of all 3D object points.
Definition: UnifiedMatching.h:212
UnifiedGuidedMatching(const Vector3 *objectPoints, const size_t numberObjectPoints, const Geometry::Octree &objectPointOctree, const Index32 *objectPointIds)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:711
virtual void determineGuidedMatchings(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, const DistanceValue &maximalDescriptorDistance, Indices32 *matchedImagePointIndices=nullptr, Indices32 *matchedObjectPointIds=nullptr, Worker *worker=nullptr) const =0
Determines the guided matching between 2D and 3D feature points.
This class implements the guided matching object for specific features.
Definition: UnifiedMatching.h:285
const UnorderedDescriptorMap< ObjectPointDescriptor > & objectPointDescriptorMap_
The map mapping object point ids to their corresponding descriptors.
Definition: UnifiedMatching.h:356
TObjectPointDescriptor ObjectPointDescriptor
Definition of the descriptor for 3D object points.
Definition: UnifiedMatching.h:295
TImagePointDescriptor ImagePointDescriptor
Definition of the descriptor for 2D image points.
Definition: UnifiedMatching.h:292
void determineGuidedMatchings(const AnyCamera &anyCamera, const HomogenousMatrix4 &world_T_camera, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, const DistanceValue &maximalDescriptorDistance, Indices32 *matchedImagePointIndices=nullptr, Indices32 *matchedObjectPointIds=nullptr, Worker *worker=nullptr) const override
Determines the guided matching between 2D and 3D feature points.
Definition: UnifiedMatching.h:775
void updateImagePoints(const Vector2 *imagePoints, const ImagePointDescriptor *imagePointDescriptors, const size_t numberImagePoints)
Updates the 2D image points e.g., to allow matching for a new camera frame.
Definition: UnifiedMatching.h:759
TDistance DescriptorDistance
Definition of the distance data type.
Definition: UnifiedMatching.h:289
UnifiedGuidedMatchingT(const Vector3 *objectPoints, const size_t numberObjectPoints, const Geometry::Octree &objectPointOctree, const Index32 *objectPointIds, const UnorderedDescriptorMap< ObjectPointDescriptor > &objectPointDescriptorMap)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:742
void clearImagePoints()
Removes the image points from this object.
Definition: UnifiedMatching.h:767
const ImagePointDescriptor * imagePointDescriptors_
The descriptors for the image points, one for each image point.
Definition: UnifiedMatching.h:353
std::unordered_map< Index32, TDescriptor > UnorderedDescriptorMap
Definition of an unordered map mapping object point ids to descriptors.
Definition: UnifiedMatching.h:301
Definition of a descriptor distance value.
Definition: UnifiedMatching.h:52
float floatDistance_
The floating point distance, with range [0, 1], -1 if unknown.
Definition: UnifiedMatching.h:110
unsigned int binaryDistance_
The binary distance, with range [0, infinity), -1 if unknown.
Definition: UnifiedMatching.h:107
bool isValid() const
Returns whether the object holds a valid distance.
Definition: UnifiedMatching.h:685
unsigned int binaryDistance() const
Returns the binary distance.
Definition: UnifiedMatching.h:658
DistanceValue()=default
Default constructor with an invalid descriptor distance.
TDistance distance() const
Returns either the binary or the floating point distance.
Definition: UnifiedMatching.h:671
float floatDistance() const
Returns the floating point distance.
Definition: UnifiedMatching.h:664
The base class for all unified matching objects.
Definition: UnifiedMatching.h:45
UnifiedMatching(const Vector3 *objectPoints, const size_t numberObjectPoints)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:690
const Vector3 * objectPoints_
The 3D object points.
Definition: UnifiedMatching.h:155
const Vector2 * imagePoints_
The 2D image points.
Definition: UnifiedMatching.h:149
const size_t numberObjectPoints_
The number of 3D object points.
Definition: UnifiedMatching.h:158
virtual ~UnifiedMatching()=default
Disposes this object.
size_t numberImagePoints_
The number of 2D image points.
Definition: UnifiedMatching.h:152
size_t numberImagePoints() const
Returns the number of image points.
Definition: UnifiedMatching.h:706
This class implements the unguided matching object for groups of FREAK Multi features with 32 bytes o...
Definition: UnifiedMatching.h:559
const ImagePointDescriptorGroup * imagePointDescriptorGroups_
The groups of descriptors for the image points, one for each image point.
Definition: UnifiedMatching.h:630
const BinaryVocabularyForest & forestObjectPointDescriptors_
The vocabulary forest for the object point features.
Definition: UnifiedMatching.h:636
bool determineUnguidedMatchings(const unsigned int minimalNumberCorrespondences, const DistanceValue &maximalDescriptorDistance, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, Worker *worker=nullptr) const override
Determines the guided matching between 2D and 3D feature points.
UnifiedUnguidedMatchingFreakMultiFeatures256Group(const Vector3 *objectPoints, const ObjectPointDescriptor *objectPointDescriptors, const size_t numberObjectPoints, const Index32 *objectPointIndices, const BinaryVocabularyForest &forestObjectPointDescriptors)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:883
void updateImagePoints(const Vector2 *imagePoints, const ImagePointDescriptorGroup *imagePointDescriptorGroups, const size_t numberImagePoints)
Updates the 2D image points e.g., to allow matching for a new camera frame.
Definition: UnifiedMatching.h:900
CV::Detector::FREAKDescriptor32 ImagePointDescriptor
Definition of the descriptor for 2D image points.
Definition: UnifiedMatching.h:566
const ObjectPointDescriptor * objectPointDescriptors_
The descriptors for the object points, one for each index in 'objectPointIndices'.
Definition: UnifiedMatching.h:633
BinaryVocabularyForest::TVocabularyTree BinaryVocabularyTree
Definition of a vocabulary tree for object point descriptors.
Definition: UnifiedMatching.h:578
const CV::Detector::FREAKDescriptors32 * ImagePointDescriptorGroup
Definition of the groups of descriptors for 2D image points.
Definition: UnifiedMatching.h:569
Tracking::VocabularyForest< ObjectPointDescriptor, DescriptorDistance, UnifiedDescriptorT< ObjectPointDescriptor >::determineDistance > BinaryVocabularyForest
Definition of a vocabulary forest for object point descriptors.
Definition: UnifiedMatching.h:575
unsigned int DescriptorDistance
Definition of the distance for the binary descriptor.
Definition: UnifiedMatching.h:563
UnifiedDescriptor::BinaryDescriptor< 256u > ObjectPointDescriptor
Definition of the descriptor for 3D object points (several descriptors per point possible).
Definition: UnifiedMatching.h:572
void clearImagePoints()
Removes the image points from this object.
Definition: UnifiedMatching.h:907
This class implements the base class for all unguided matching objects.
Definition: UnifiedMatching.h:227
virtual bool determineUnguidedMatchings(const unsigned int minimalNumberCorrespondences, const DistanceValue &maximalDescriptorDistance, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, Worker *worker=nullptr) const =0
Determines the unguided matching between 2D and 3D feature points.
UnifiedUnguidedMatching(const Vector3 *objectPoints, const size_t numberObjectPoints, const Index32 *objectPointIndices)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:727
const Index32 * objectPointIndices_
The indices of the corresponding 3D object points, one for each object point descriptor,...
Definition: UnifiedMatching.h:266
This class implements the unguided matching object for FREAK Multi features with 32 bytes or 256 bits...
Definition: UnifiedMatching.h:382
VocabularyForest::TVocabularyTree VocabularyTree
Definition of a vocabulary tree for object point descriptors.
Definition: UnifiedMatching.h:398
Tracking::VocabularyForest< ObjectPointVocabularyDescriptor, DescriptorDistance, UnifiedDescriptorT< ObjectPointVocabularyDescriptor >::determineDistance > VocabularyForest
Definition of a vocabulary forest for object point descriptors.
Definition: UnifiedMatching.h:395
void clearImagePoints()
Removes the image points from this object.
Definition: UnifiedMatching.h:808
TImagePointDescriptor ImagePointDescriptor
Definition of the descriptor for 2D image points.
Definition: UnifiedMatching.h:389
bool determineUnguidedMatchings(const unsigned int minimalNumberCorrespondences, const DistanceValue &maximalDescriptorDistance, Vectors2 &matchedImagePoints, Vectors3 &matchedObjectPoints, Worker *worker=nullptr) const override
Determines the unguided matching between 2D and 3D feature points.
Definition: UnifiedMatching.h:816
const VocabularyForest & forestObjectPointDescriptors_
The vocabulary forest for the object point features.
Definition: UnifiedMatching.h:456
TDistance DescriptorDistance
Definition of the distance for the binary descriptor.
Definition: UnifiedMatching.h:386
const ImagePointDescriptor * imagePointDescriptors_
The descriptors for the image points, one for each image point.
Definition: UnifiedMatching.h:450
UnifiedUnguidedMatchingT(const Vector3 *objectPoints, const ObjectPointVocabularyDescriptor *objectPointVocabularyDescriptors, const size_t numberObjectPoints, const Index32 *objectPointIndices, const VocabularyForest &forestObjectPointDescriptors)
Creates a new matching object with 3D object points only.
Definition: UnifiedMatching.h:781
TObjectPointVocabularyDescriptor ObjectPointVocabularyDescriptor
Definition of the descriptor for 3D object points.
Definition: UnifiedMatching.h:392
void updateImagePoints(const Vector2 *imagePoints, const ImagePointDescriptor *imagePointDescriptors, const size_t numberImagePoints)
Updates the 2D image points e.g., to allow matching for a new camera frame.
Definition: UnifiedMatching.h:800
const ObjectPointVocabularyDescriptor * objectPointVocabularyDescriptors_
The descriptors for the object points, one for each index in 'objectPointIndices'.
Definition: UnifiedMatching.h:453
This class implements a Vocabulary Forest holding several Vocabulary Trees.
Definition: VocabularyTree.h:766
Matches< TDistance > Matches
Definition of a vector holding Match objects.
Definition: VocabularyTree.h:807
This class implements a Vocabulary Tree for feature descriptors.
Definition: VocabularyTree.h:223
Match< TDistance > Match
Definition of a Match object using the distance data type of this tree.
Definition: VocabularyTree.h:274
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
uint32_t Index32
Definition of a 32 bit index value.
Definition: Base.h:84
OctreeT< Scalar > Octree
Definition of an Octree using Scalar as data type.
Definition: Octree.h:25
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition: Vector2.h:64
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition: Vector3.h:65
std::shared_ptr< UnifiedGuidedMatching > SharedUnifiedGuidedMatching
Definition of a shared pointer holding an UnifiedGuidedMatching object.
Definition: UnifiedMatching.h:220
std::shared_ptr< UnifiedUnguidedMatching > SharedUnifiedUnguidedMatching
Definition of a shared pointer holding an UnifiedUnguidedMatching object.
Definition: UnifiedMatching.h:274
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