Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit 852f06c

Browse files
committed
Merge remote-tracking branch 'origin/feature/SLAMOptimization' into develop
2 parents 43e8fc4 + c46441b commit 852f06c

File tree

41 files changed

+243
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+243
-166
lines changed

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ Release/
5757
*-packagedependencies-unix.*
5858
*-packagedependencies-android.*
5959
*.pc
60-
*-Debug
61-
*-Release
60+
*-Debug*
61+
*-Release*
62+
*_Debug*
63+
*_Release*
6264

6365
# Executables
6466
*.exe

SolARModuleTools.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CONFIG -= qt
66
INSTALLSUBDIR = SolARBuild
77
TARGET = SolARModuleTools
88
FRAMEWORK = $$TARGET
9-
VERSION=0.9.0
9+
VERSION=0.9.1
1010

1111
DEFINES += MYVERSION=$${VERSION}
1212
DEFINES += TEMPLATE_LIBRARY

bcom-SolARModuleTools.pc.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ libdir=${exec_prefix}/lib
55
includedir=${prefix}/interfaces
66
Name: SolARModuleTools
77
Description:
8-
Version: 0.9.0
8+
Version: 0.9.1
99
Requires:
1010
Libs: -L${libdir} -l${libname}
1111
Libs.private: ${libdir}/${pfx}${libname}.${lext}

interfaces/SolARFiducialMarkerPoseEstimator.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
#include "api/features/IDescriptorsExtractorSBPattern.h"
2727
#include "api/features/ISBPatternReIndexer.h"
2828
#include "api/geom/IImage2WorldMapper.h"
29+
#include "api/geom/IProject.h"
2930
#include "api/solver/pose/I3DTransformFinderFrom2D3D.h"
31+
#include "api/features/ICornerRefinement.h"
3032
#include "datastructure/Image.h"
3133
#include "datastructure/FiducialMarker.h"
3234
#include "SolARToolsAPI.h"
@@ -53,6 +55,7 @@ namespace TOOLS {
5355
* @SolARComponentInjectable{SolAR::api::features::ISBPatternReIndexer}
5456
* @SolARComponentInjectable{SolAR::api::geom::IImage2WorldMapper}
5557
* @SolARComponentInjectable{SolAR::api::solver::pose::I3DTransformFinderFrom2D3D}
58+
* @SolARComponentInjectable{SolAR::api::features::ICornerRefinement}
5659
* @SolARComponentInjectablesEnd
5760
*
5861
* @SolARComponentPropertiesBegin
@@ -112,10 +115,13 @@ class SOLAR_TOOLS_EXPORT_API SolARFiducialMarkerPoseEstimator : public org::bcom
112115
SRef<api::features::ISBPatternReIndexer> m_patternReIndexer;
113116
SRef<api::geom::IImage2WorldMapper> m_img2worldMapper;
114117
SRef<api::solver::pose::I3DTransformFinderFrom2D3D> m_pnp;
118+
SRef<api::features::ICornerRefinement> m_cornerRefinement;
119+
SRef<api::geom::IProject> m_projector;
115120
SRef<datastructure::DescriptorBuffer> m_markerPatternDescriptor;
116121
int m_nbThreshold = 3;
117122
int m_minThreshold = -1;
118123
int m_maxThreshold = 220;
124+
float m_maxReprojError = 0.5f;
119125
};
120126

121127
}

interfaces/SolARSLAMBootstrapper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "api/solver/map/IKeyframeSelector.h"
2929
#include "api/display/IMatchesOverlay.h"
3030
#include "api/solver/pose/I3DTransformFinderFrom2D2D.h"
31+
#include "api/geom/IUndistortPoints.h"
3132
#include "SolARToolsAPI.h"
3233
#include "xpcf/component/ConfigurableBase.h"
3334

@@ -75,6 +76,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMBootstrapper : public org::bcom::xpcf::Con
7576
SolARSLAMBootstrapper();
7677
///@brief SolAR3DTransformEstimationFrom3D3D destructor;
7778
~SolARSLAMBootstrapper() = default;
79+
7880
/// @brief this method is used to set intrinsic parameters and distorsion of the camera
7981
/// @param[in] Camera calibration matrix parameters.
8082
/// @param[in] Camera distorsion parameters.
@@ -88,6 +90,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMBootstrapper : public org::bcom::xpcf::Con
8890
FrameworkReturnCode process(const SRef<datastructure::Image> image, SRef<datastructure::Image> & view, const datastructure::Transform3Df & pose = datastructure::Transform3Df::Identity()) override;
8991

9092
void unloadComponent() override final;
93+
org::bcom::xpcf::XPCFErrorCode onConfigured() override final;
9194

9295
private:
9396
/// bootstrap uses marker
@@ -99,6 +102,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMBootstrapper : public org::bcom::xpcf::Con
99102
int m_hasPose = 1;
100103
int m_nbMinInitPointCloud = 50;
101104
float m_angleThres = 0.1f;
105+
float m_ratioDistanceIsKeyframe = 0.05f;
102106
bool m_bootstrapOk = false;
103107
bool m_initKeyframe1 = false;
104108
SRef<datastructure::Keyframe> m_keyframe1, m_keyframe2;
@@ -113,6 +117,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMBootstrapper : public org::bcom::xpcf::Con
113117
SRef<api::solver::map::IMapFilter> m_mapFilter;
114118
SRef<api::solver::map::IKeyframeSelector> m_keyframeSelector;
115119
SRef<api::solver::pose::I3DTransformFinderFrom2D2D> m_poseFinderFrom2D2D;
120+
SRef<api::geom::IUndistortPoints> m_undistortPoints;
116121
SRef<api::display::IMatchesOverlay> m_matchesOverlay;
117122
};
118123

interfaces/SolARSLAMMapping.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,12 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMMapping : public org::bcom::xpcf::Configur
105105

106106
private:
107107
float m_minWeightNeighbor = 1.f;
108-
int m_minTrackedPoints = 100;
108+
int m_minTrackedPoints = 200;
109109
int m_maxNbNeighborKfs = 5;
110+
int m_nbPassedFrames = 0;
111+
int m_nbVisibilityAtLeast = 30;
112+
int m_nbPassedFrameAtLeast = 5;
113+
float m_ratioCPRefKeyframe = 0.5;
110114
SRef<datastructure::Keyframe> m_updatedReferenceKeyframe;
111115
datastructure::CamCalibration m_camMatrix;
112116
datastructure::CamDistortion m_camDistortion;

interfaces/SolARSLAMTracking.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMTracking : public org::bcom::xpcf::Configu
9393
FrameworkReturnCode process(const SRef<datastructure::Frame> frame, SRef<datastructure::Image> &displayImage) override;
9494

9595
void unloadComponent() override final;
96+
org::bcom::xpcf::XPCFErrorCode onConfigured() override final;
9697

9798
private:
9899
void updateLocalMap();
@@ -104,6 +105,7 @@ class SOLAR_TOOLS_EXPORT_API SolARSLAMTracking : public org::bcom::xpcf::Configu
104105
bool m_isLostTrack = false;
105106
float m_minWeightNeighbor = 10.f;
106107
float m_thresAngleViewDirection = 0.7f;
108+
float m_reprojErrorThreshold;
107109
int m_displayTrackedPoints = 1;
108110
bool m_isUpdateReferenceKeyframe = false;
109111
std::mutex m_refKeyframeMutex;

packagedependencies.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SolARFramework|0.9.0|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download
1+
SolARFramework|0.9.1|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download

src/SolARFiducialMarkerPoseEstimator.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,19 @@ SolARFiducialMarkerPoseEstimator::SolARFiducialMarkerPoseEstimator():Configurabl
4343
declareInjectable<api::features::ISBPatternReIndexer>(m_patternReIndexer);
4444
declareInjectable<api::geom::IImage2WorldMapper>(m_img2worldMapper);
4545
declareInjectable<api::solver::pose::I3DTransformFinderFrom2D3D>(m_pnp);
46+
declareInjectable<api::features::ICornerRefinement>(m_cornerRefinement);
47+
declareInjectable<api::geom::IProject>(m_projector);
4648
declareProperty("nbThreshold", m_nbThreshold);
4749
declareProperty("minThreshold", m_minThreshold);
4850
declareProperty("maxThreshold", m_maxThreshold);
51+
declareProperty("maxReprojError", m_maxReprojError);
4952
}
5053

5154
void SolARFiducialMarkerPoseEstimator::setCameraParameters(const CamCalibration & intrinsicParams, const CamDistortion & distortionParams) {
5255
m_camMatrix = intrinsicParams;
5356
m_camDistortion = distortionParams;
5457
m_pnp->setCameraParameters(m_camMatrix, m_camDistortion);
58+
m_projector->setCameraParameters(m_camMatrix, m_camDistortion);
5559
// components initialisation for marker detection
5660
m_binaryMarker->loadMarker();
5761
m_patternDescriptorExtractor->extract(m_binaryMarker->getPattern(), m_markerPatternDescriptor);
@@ -136,10 +140,22 @@ FrameworkReturnCode SolARFiducialMarkerPoseEstimator::estimate(const SRef<Image>
136140
m_patternReIndexer->reindex(recognizedContours, patternMatches, pattern2DPoints, img2DPoints);
137141
// Compute the 3D position of each corner of the marker
138142
m_img2worldMapper->map(pattern2DPoints, pattern3DPoints);
143+
// Refine corner locations
144+
m_cornerRefinement->refine(greyImage, img2DPoints);
139145
// Compute the pose of the camera using a Perspective n Points algorithm using only the 4 corners of the marker
140146
if (m_pnp->estimate(img2DPoints, pattern3DPoints, pose) == FrameworkReturnCode::_SUCCESS)
141147
{
142-
return FrameworkReturnCode::_SUCCESS;
148+
std::vector<Point2Df> projected2DPts;
149+
m_projector->project(pattern3DPoints, projected2DPts, pose);
150+
float errorReproj(0.f);
151+
for (int j = 0; j < projected2DPts.size(); ++j)
152+
errorReproj += (projected2DPts[j] - img2DPoints[j]).norm();
153+
errorReproj /= projected2DPts.size();
154+
LOG_DEBUG("Mean reprojection error: {}", errorReproj);
155+
if (errorReproj < m_maxReprojError)
156+
return FrameworkReturnCode::_SUCCESS;
157+
pose = Transform3Df::Identity();
158+
return FrameworkReturnCode::_ERROR_;
143159
}
144160
}
145161
}

src/SolARLoopClosureDetector.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ FrameworkReturnCode SolARLoopClosureDetector::detect(const SRef<Keyframe> queryK
6161
for (auto &it : retKeyframesIndex) {
6262
std::vector<uint32_t> paths;
6363
m_covisibilityGraph->getShortestPath(queryKeyframeId, it, paths);
64-
if (paths.size() > 3)
64+
if (paths.size() > 3) {
6565
candidatesId.push_back(it);
66+
if (candidatesId.size() >= 3)
67+
break;
68+
}
6669
}
6770
std::vector<SRef<Keyframe>> candidateKeyframes;
6871
std::vector<Transform3Df> candidateKeyframePoses;

0 commit comments

Comments
 (0)