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

Commit bac535b

Browse files
author
BCOM\nduong
committed
Merge branch 'develop' into feature/OptimizedMatches
2 parents c6a55e6 + cb2333c commit bac535b

File tree

102 files changed

+2404
-1876
lines changed

Some content is hidden

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

102 files changed

+2404
-1876
lines changed

SolARModuleOpenCV.pri

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ HEADERS += interfaces/SolAR2D3DcorrespondencesFinderOpencv.h \
1111
interfaces/SolARDescriptorMatcherHammingBruteForceOpencv.h \
1212
interfaces/SolARDescriptorMatcherKNNOpencv.h \
1313
interfaces/SolARDescriptorMatcherRadiusOpencv.h \
14+
interfaces/SolARDescriptorMatcherGeometricOpencv.h \
15+
interfaces/SolARDescriptorMatcherRegionOpencv.h \
1416
interfaces/SolARDescriptorsExtractorAKAZE2Opencv.h \
1517
interfaces/SolARDescriptorsExtractorAKAZEOpencv.h \
1618
interfaces/SolARDescriptorsExtractorORBOpencv.h \
@@ -47,6 +49,10 @@ HEADERS += interfaces/SolAR2D3DcorrespondencesFinderOpencv.h \
4749
interfaces/SolARPoseEstimationSACPnpOpencv.h \
4850
interfaces/SolARPoseFinderFrom2D2DOpencv.h \
4951
interfaces/SolARProjectOpencv.h \
52+
interfaces/SolARStereo2DPointsRectificationOpencv.h \
53+
interfaces/SolARStereoCalibrationOpencv.h \
54+
interfaces/SolARStereoDescriptorMatcherOpencv.h \
55+
interfaces/SolARStereoImageRectificationOpencv.h \
5056
interfaces/SolARSVDFundamentalMatrixDecomposerOpencv.h\
5157
interfaces/SolARUndistortPointsOpencv.h \
5258
interfaces/SolARUnprojectPlanarPointsOpencv.h \
@@ -77,6 +83,8 @@ SOURCES += src/AKAZE2/akaze.cpp \
7783
src/SolARDescriptorMatcherHammingBruteForceOpencv.cpp \
7884
src/SolARDescriptorMatcherKNNOpencv.cpp \
7985
src/SolARDescriptorMatcherRadiusOpencv.cpp \
86+
src/SolARDescriptorMatcherGeometricOpencv.cpp \
87+
src/SolARDescriptorMatcherRegionOpencv.cpp \
8088
src/SolARDescriptorsExtractorAKAZE2Opencv.cpp \
8189
src/SolARDescriptorsExtractorAKAZEOpencv.cpp \
8290
src/SolARDescriptorsExtractorORBOpencv.cpp \
@@ -111,6 +119,10 @@ SOURCES += src/AKAZE2/akaze.cpp \
111119
src/SolARPoseEstimationSACPnpOpencv.cpp \
112120
src/SolARPoseFinderFrom2D2DOpencv.cpp \
113121
src/SolARProjectOpencv.cpp \
122+
src/SolARStereo2DPointsRectificationOpencv.cpp \
123+
src/SolARStereoCalibrationOpencv.cpp \
124+
src/SolARStereoDescriptorMatcherOpencv.cpp \
125+
src/SolARStereoImageRectificationOpencv.cpp \
114126
src/SolARSVDFundamentalMatrixDecomposerOpencv.cpp \
115127
src/SolARSVDTriangulationOpencv.cpp \
116128
src/SolARUndistortPointsOpencv.cpp \

SolARModuleOpenCV.pro

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
QT -= core gui
33
CONFIG -= qt
44

5+
QMAKE_PROJECT_DEPTH = 0
6+
57
## global defintions : target lib name, version
68
INSTALLSUBDIR = SolARBuild
79
TARGET = SolARModuleOpenCV
810
FRAMEWORK = $$TARGET
9-
VERSION=0.9.3
11+
VERSION=0.10.0
1012

1113
DEFINES += MYVERSION=$${VERSION}
1214
DEFINES += TEMPLATE_LIBRARY
@@ -59,6 +61,7 @@ macx {
5961
QMAKE_CXXFLAGS += -mmacosx-version-min=10.7 -std=c11 -std=c++11 -O3 -fPIC#-x objective-c++
6062
QMAKE_LFLAGS += -mmacosx-version-min=10.7 -v -lstdc++
6163
LIBS += -lstdc++ -lc -lpthread
64+
LIBS += -L/usr/local/lib
6265
}
6366

6467
win32 {

bcom-SolARModuleOpenCV.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: SolARModuleOpenCV
77
Description:
8-
Version: 0.9.4
8+
Version: 0.10.0
99
Requires:
1010
Libs: -L${libdir} -l${libname}
1111
Libs.private: ${libdir}/${pfx}${libname}.${lext}

interfaces/SolARCameraCalibrationOpencv.h

Lines changed: 22 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include <string>
2323
#include "opencv2/videoio.hpp"
24-
#include "xpcf/component/ComponentBase.h"
24+
#include "xpcf/component/ConfigurableBase.h"
2525

2626
#include "SolAROpencvAPI.h"
2727

@@ -37,93 +37,38 @@ namespace OPENCV {
3737
*/
3838

3939
class SOLAROPENCV_EXPORT_API SolARCameraCalibrationOpencv :
40-
public org::bcom::xpcf::ComponentBase,
40+
public org::bcom::xpcf::ConfigurableBase,
4141
public api::input::devices::ICameraCalibration
4242
{
4343
public:
44-
enum ProcessMode
45-
{
46-
SOLAR_DETECT = 0,
47-
SOLAR_CAPTURE = 1,
48-
SOLAR_CALIBRATED = 2
49-
};
44+
SolARCameraCalibrationOpencv();
45+
~SolARCameraCalibrationOpencv() override;
46+
/// @brief Calibrate the camera device from a sequence of images
47+
/// @param[in] images The set of images for calibration
48+
/// @param[out] camParams The camera paramters
49+
/// @return FrameworkReturnCode::_SUCCESS if calibration succeed, else FrameworkReturnCode::_ERROR_
50+
FrameworkReturnCode calibrate(const std::vector<SRef<SolAR::datastructure::Image>>& images,
51+
SolAR::datastructure::CameraParameters & camParams) override;
5052

51-
public:
52-
SolARCameraCalibrationOpencv();
53-
virtual ~SolARCameraCalibrationOpencv() override;
54-
/// @brief this method calibrates and fixes an unkonwn camera intrinsic parameters from a offline video stream,
55-
/// it saves the result calibration file inside output folder.
56-
/// @param[in] inputVideo: path of the video stream captured by the unkown camera.
57-
/// @param[out] output: path of the folder where a result calibration file will be written.
58-
bool calibrate(const std::string & inputVideo, const std::string & output) override;
59-
/// @brief this method calibrates and fixes an unkonwn camera intrinsic parameters from a online video stream,
60-
/// it saves the result calibration file inside output folder.
61-
/// @param[in] camera_id: id of the unkown camera from which the video stream is grabbed.
62-
/// @param[out] output: path of the folder where a result calibration file will be written.
63-
bool calibrate(int camera_id, const std::string & output) override;
64-
/// @brief this method is used to set intrinsic parameters and distorsion of the camera
65-
/// @param[in] Camera calibration matrix parameters.
66-
/// @param[in] Camera distorsion parameters.
67-
bool setParameters(const std::string & config_file) override;
68-
virtual void unloadComponent() override;
53+
void unloadComponent() override;
6954

55+
private:
56+
bool findChessboardCornersImage(SRef<SolAR::datastructure::Image>& image,
57+
cv::Mat & displayImage,
58+
std::vector<cv::Point2f>& corners);
7059

7160
private:
72-
protected:
61+
cv::Mat m_camMatrix;
62+
cv::Mat m_camDistortion;
7363
cv::Size m_boardSize;
74-
cv::Size m_imageSize;
75-
cv::Mat m_camMatrix;
76-
cv::Mat m_camDistorsion;
77-
64+
cv::Size m_imageSize;
7865
float m_squareSize;
79-
float m_aspectRatio;
80-
81-
int m_nframes;
66+
int m_nbFrames = 30;
67+
int m_nbDropFrames = 0;
8268
int m_flags;
83-
int m_delay;
84-
85-
virtual bool process(cv::VideoCapture &, const std::string &);
86-
87-
static double computeReprojectionErrors(const std::vector<std::vector<cv::Point3f> >& objectPoints,
88-
const std::vector<std::vector<cv::Point2f> >& imagePoints,
89-
const std::vector<cv::Mat>& rvecs, const std::vector<cv::Mat>& tvecs,
90-
const cv::Mat& cameraMatrix, const cv::Mat& distCoeffs,
91-
std::vector<float>& perViewErrors);
92-
93-
static void calcChessboardCorners(cv::Size boardSize, float squareSize, std::vector<cv::Point3f>& corners);
94-
95-
static bool runCalibration(const std::vector<std::vector<cv::Point2f>> & imagePoints,
96-
cv::Size imageSize,
97-
cv::Size boardSize,
98-
float squareSize,
99-
float aspectRatio,
100-
int flags,
101-
cv::Mat& cameraMatrix,
102-
cv::Mat& distCoeffs,
103-
std::vector<cv::Mat>& rvecs,
104-
std::vector<cv::Mat>& tvecs,
105-
std::vector<float>& reprojErrs,
106-
double& totalAvgErr);
107-
108-
static void saveCameraParams(const std::string& filename,
109-
cv::Size imageSize,
110-
cv::Size boardSize,
111-
float squareSize,
112-
float aspectRatio,
113-
int flags,
114-
const cv::Mat& cameraMatrix,
115-
const cv::Mat& distCoeffs);
116-
117-
static bool runAndSave(const std::string& outputFilename,
118-
const std::vector<std::vector<cv::Point2f> >& imagePoints,
119-
cv::Size imageSize,
120-
cv::Size boardSize,
121-
float squareSize,
122-
float aspectRatio,
123-
int flags,
124-
cv::Mat& cameraMatrix,
125-
cv::Mat& distCoeffs);
69+
int m_waitTime = 30;
12670
};
71+
12772
}
12873
}
12974
} // end of namespace Solar
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/**
2+
* @copyright Copyright (c) 2017 B-com http://www.b-com.com/
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef SOLARDESCRIPTORMATCHERGEOMETRICOPENCV_H
18+
#define SOLARDESCRIPTORMATCHERGEOMETRICOPENCV_H
19+
20+
#include "base/features/ADescriptorMatcherGeometric.h"
21+
#include "SolAROpencvAPI.h"
22+
#include <limits>
23+
#include "opencv2/core.hpp"
24+
#include "opencv2/features2d.hpp"
25+
#include "opencv2/imgcodecs.hpp"
26+
#include "opencv2/highgui.hpp"
27+
#include <opencv2/calib3d.hpp>
28+
29+
namespace SolAR {
30+
namespace MODULES {
31+
namespace OPENCV {
32+
33+
/**
34+
* @class SolARDescriptorMatcherGeometricOpencv
35+
* @brief <B>Matches two sets of descriptors based on geometric constraints.</B>
36+
* <TT>UUID: 389ece8b-9e29-45ae-bd60-de1784ff0931</TT>
37+
*
38+
* @SolARComponentPropertiesBegin
39+
* @SolARComponentProperty{ distanceRatio,
40+
* distance ratio used to keep good matches.<br/>
41+
* Several matches can correspond to a given keypoint of the first image. The first match with the best score is always retained.<br>
42+
* But here\, we can also retain the second match if its distance or score is greater than the score of the best match * m_distanceRatio.,
43+
* @SolARComponentPropertyDescNum{ float, [0..MAX FLOAT], default: 0.75f }}
44+
* @SolARComponentProperty{ paddingRatio,
45+
* ,
46+
* @SolARComponentPropertyDescNum{ float, [0..MAX FLOAT], 0.003f }}
47+
* @SolARComponentProperty{ matchingDistanceMax,
48+
* ,
49+
* @SolARComponentPropertyDescNum{ float, [0..MAX FLOAT], 500.f }}
50+
* @SolARComponentPropertiesEnd
51+
*
52+
*
53+
*/
54+
55+
class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherGeometricOpencv : public base::features::ADescriptorMatcherGeometric {
56+
public:
57+
/// @brief SolARDescriptorMatcherGeometricOpencv constructor
58+
SolARDescriptorMatcherGeometricOpencv();
59+
60+
/// @brief SolARDescriptorMatcherGeometricOpencv destructor
61+
~SolARDescriptorMatcherGeometricOpencv() override;
62+
63+
/// @brief Match two sets of descriptors from two frames based on epipolar constraint.
64+
/// @param[in] descriptors1 The first set of descriptors.
65+
/// @param[in] descriptors2 The second set of descriptors.
66+
/// @param[in] undistortedKeypoints1 The first set of undistorted keypoints.
67+
/// @param[in] undistortedKeypoints2 The second set of undistorted keypoints.
68+
/// @param[in] pose1 The first pose.
69+
/// @param[in] pose2 The second pose.
70+
/// @param[in] camParams The intrinsic parameters of the camera.
71+
/// @param[out] matches A vector of matches representing pairs of indices relatively to the first and second set of descriptors.
72+
/// @param[in] mask The indices of descriptors in the first frame are used for matching to the second frame. If it is empty then all will be used.
73+
/// @return FrameworkReturnCode::_SUCCESS if matching succeed, else FrameworkReturnCode::_ERROR_
74+
FrameworkReturnCode match(const SRef<SolAR::datastructure::DescriptorBuffer> descriptors1,
75+
const SRef<SolAR::datastructure::DescriptorBuffer> descriptors2,
76+
const std::vector<SolAR::datastructure::Keypoint> &undistortedKeypoints1,
77+
const std::vector<SolAR::datastructure::Keypoint> &undistortedKeypoints2,
78+
const SolAR::datastructure::Transform3Df& pose1,
79+
const SolAR::datastructure::Transform3Df& pose2,
80+
const SolAR::datastructure::CameraParameters& camParams,
81+
std::vector<SolAR::datastructure::DescriptorMatch> & matches,
82+
const std::vector<uint32_t>& mask = {}) override;
83+
84+
void unloadComponent() override;
85+
86+
private:
87+
float m_distanceRatio = 0.75f;
88+
float m_paddingRatio = 0.003f;
89+
float m_matchingDistanceMax = 500.f;
90+
cv::FlannBasedMatcher m_matcher;
91+
92+
};
93+
94+
}
95+
}
96+
} // end of namespace SolAR
97+
98+
#endif // SOLARDESCRIPTORMATCHERGEOMETRICOPENCV_H

interfaces/SolARDescriptorMatcherHammingBruteForceOpencv.h

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,14 @@
1717
#ifndef SOLARDESCRIPTORMATCHERHAMMINGBRUTEFORCEMOPENCV_H
1818
#define SOLARDESCRIPTORMATCHERHAMMINGBRUTEFORCEMOPENCV_H
1919

20-
#include "api/features/IDescriptorMatcher.h"
21-
22-
// Definition of SolARDescriptorMatcherOpencv Class //
23-
// part of SolAR namespace //
24-
25-
#include "xpcf/component/ConfigurableBase.h"
20+
#include "base/features/ADescriptorMatcher.h"
2621
#include "SolAROpencvAPI.h"
2722
#include <string>
2823
#include "opencv2/core.hpp"
2924
#include "opencv2/features2d.hpp"
3025
#include "opencv2/imgcodecs.hpp"
3126
#include "opencv2/highgui.hpp"
3227

33-
#include "datastructure/DescriptorMatch.h"
34-
#include "datastructure/DescriptorBuffer.h"
35-
3628
namespace SolAR {
3729
namespace MODULES {
3830
namespace OPENCV {
@@ -53,39 +45,27 @@ namespace OPENCV {
5345
*
5446
*/
5547

56-
class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherHammingBruteForceOpencv : public org::bcom::xpcf::ConfigurableBase,
57-
public api::features::IDescriptorMatcher {
48+
class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherHammingBruteForceOpencv : public base::features::ADescriptorMatcher {
5849
public:
5950
SolARDescriptorMatcherHammingBruteForceOpencv();
6051
~SolARDescriptorMatcherHammingBruteForceOpencv() override;
61-
void unloadComponent () override final;
6252

63-
/// @brief Matches two descriptors desc1 and desc2 respectively based on hamming distance
64-
/// [in] desc1: source descriptor.
65-
/// [in] desc2: target descriptor.
66-
/// [out] matches: ensemble of detected matches, a pair of source/target indices.
67-
///@return IDescriptorMatcher::RetCode::DESCRIPTORS_MATCHER_OK if succeed.
68-
IDescriptorMatcher::RetCode match(
69-
const SRef<datastructure::DescriptorBuffer> desc1,
70-
const SRef<datastructure::DescriptorBuffer> desc2,
71-
std::vector<datastructure::DescriptorMatch> & matches) override;
72-
/// @brief Matches a descriptor desc1 with an ensemble of descriptors desc2 based on hamming distance
73-
/// [in] desc1: source descriptor.
74-
/// [in] desc2: target descriptors.
75-
/// [out] matches: ensemble of detected matches, a pair of source/target indices.
76-
///@return IDescriptorMatcher::RetCode::DESCRIPTORS_MATCHER_OK if succeed.
77-
IDescriptorMatcher::RetCode match(
78-
const SRef<datastructure::DescriptorBuffer> descriptors1,
79-
const std::vector<SRef<datastructure::DescriptorBuffer>> & descriptors2,
80-
std::vector<datastructure::DescriptorMatch> & matches) override;
53+
/// @brief Match two sets of descriptors together
54+
/// @param[in] descriptors1 The first set of descriptors organized in a dedicated buffer structure.
55+
/// @param[in] descriptors2 The second set of descriptors organized in a dedicated buffer structure.
56+
/// @param[out] matches A vector of matches representing pairs of indices relatively to the first and second set of descriptors.
57+
/// @return FrameworkReturnCode::_SUCCESS if matching succeed, else FrameworkReturnCode::_ERROR_
58+
FrameworkReturnCode match(const SRef<SolAR::datastructure::DescriptorBuffer> descriptors1,
59+
const SRef<SolAR::datastructure::DescriptorBuffer> descriptors2,
60+
std::vector<SolAR::datastructure::DescriptorMatch> & matches) override;
61+
62+
void unloadComponent() override;
8163

8264
private:
8365
/// @brief distance ratio used to keep good matches.
8466
/// Several matches can correspond to a given keypoint of the first image. The first match with the best score is always retained.
8567
/// But here, we can also retain the next matches if their distances or scores is greater than the score of the best match * m_distanceRatio.
8668
float m_distanceRatio = 0.75f;
87-
88-
8969
int m_id;
9070
cv::BFMatcher m_matcher;
9171

0 commit comments

Comments
 (0)