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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-bcom committed Aug 26, 2021
2 parents 9695a5b + d6bda89 commit e812dbf
Show file tree
Hide file tree
Showing 67 changed files with 1,194 additions and 403 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ Release/
*-packagedependencies-unix.*
*-packagedependencies-android.*
*.pc
*-Debug
*-Release
*-Debug*
*-Release*
*_Debug*
*_Release*

# Executables
*.exe
Expand Down
2 changes: 2 additions & 0 deletions SolARModuleOpenCV.pri
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ HEADERS += interfaces/SolAR2D3DcorrespondencesFinderOpencv.h \
interfaces/SolARCameraOpencv.h \
interfaces/SolARContoursExtractorOpencv.h \
interfaces/SolARContoursFilterBinaryMarkerOpencv.h \
interfaces/SolARCornerRefinementOpencv.h \
interfaces/SolARDescriptorMatcherHammingBruteForceOpencv.h \
interfaces/SolARDescriptorMatcherKNNOpencv.h \
interfaces/SolARDescriptorMatcherRadiusOpencv.h \
Expand Down Expand Up @@ -70,6 +71,7 @@ SOURCES += src/AKAZE2/akaze.cpp \
src/SolARCameraOpencv.cpp \
src/SolARContoursExtractorOpencv.cpp \
src/SolARContoursFilterBinaryMarkerOpencv.cpp \
src/SolARCornerRefinementOpencv.cpp \
src/SolARDescriptorMatcherHammingBruteForceOpencv.cpp \
src/SolARDescriptorMatcherKNNOpencv.cpp \
src/SolARDescriptorMatcherRadiusOpencv.cpp \
Expand Down
2 changes: 1 addition & 1 deletion SolARModuleOpenCV.pro
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CONFIG -= qt
INSTALLSUBDIR = SolARBuild
TARGET = SolARModuleOpenCV
FRAMEWORK = $$TARGET
VERSION=0.9.0
VERSION=0.9.1

DEFINES += MYVERSION=$${VERSION}
DEFINES += TEMPLATE_LIBRARY
Expand Down
2 changes: 1 addition & 1 deletion bcom-SolARModuleOpenCV.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ libdir=${exec_prefix}/lib
includedir=${prefix}/interfaces
Name: SolARModuleOpenCV
Description:
Version: 0.9.0
Version: 0.9.1
Requires:
Libs: -L${libdir} -l${libname}
Libs.private: ${libdir}/${pfx}${libname}.${lext}
Expand Down
68 changes: 68 additions & 0 deletions interfaces/SolARCornerRefinementOpencv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @copyright Copyright (c) 2017 B-com http://www.b-com.com/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef SOLARCORNERREFINEMENTOPENCV_H
#define SOLARCORNERREFINEMENTOPENCV_H

#include "xpcf/component/ConfigurableBase.h"
#include "SolAROpencvAPI.h"
#include "api/features/ICornerRefinement.h"
#include "opencv2/core.hpp"
#include <vector>

namespace SolAR {
namespace MODULES {
namespace OPENCV {

/**
* @class SolARCornerRefinementOpencv
* @brief <B>Refine the corner locations.</B>
* <TT>UUID: ddae46ca-1657-4301-a87d-f2dcfa6265d0</TT>
*
*/

class SOLAROPENCV_EXPORT_API SolARCornerRefinementOpencv : public org::bcom::xpcf::ConfigurableBase,
public api::features::ICornerRefinement
{
public:
/// @brief SolARCornerRefinementOpencv constructor
SolARCornerRefinementOpencv();

/// @brief SolARCornerRefinementOpencv default destructor
~SolARCornerRefinementOpencv() = default;

/// @brief This method refines the corner locations
/// @param[in] image Input image on which we are extracting keypoints.
/// @param[in,out] corners Initial coordinates of the input corners and refined coordinates provided for output.
void refine(const SRef<datastructure::Image> image, std::vector<datastructure::Point2Df> & corners) override;

org::bcom::xpcf::XPCFErrorCode onConfigured() override final;

void unloadComponent () override final;

private:
uint32_t m_nbMaxIters = 40;
float m_minAccuracy = 0.01;
cv::TermCriteria m_termcrit;
uint32_t m_winSize = 5;
cv::Size m_subPixWinSize;
};

}
}
}

#endif // SOLARCORNERREFINEMENTOPENCV_H
34 changes: 22 additions & 12 deletions interfaces/SolARDescriptorMatcherKNNOpencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherKNNOpencv : public org::bcom:
/// [in] desc2: target descriptor.
/// [out] matches: ensemble of detected matches, a pair of source/target indices.
///@return IDescriptorMatcher::RetCode::DESCRIPTORS_MATCHER_OK if succeed.
IDescriptorMatcher::RetCode match(
IDescriptorMatcher::RetCode match(
const SRef<datastructure::DescriptorBuffer> desc1,
const SRef<datastructure::DescriptorBuffer> desc2,
std::vector<datastructure::DescriptorMatch> & matches) override;
/// @brief Matches a descriptor desc1 with an ensemble of descriptors desc2 based on KNN search strategy.
/// [in] desc1: source descriptor.
/// [in] desc2: target descriptors.
/// [out] matches: ensemble of detected matches, a pair of source/target indices.
///@return IDescriptorMatcher::RetCode::DESCRIPTORS_MATCHER_OK if succeed.
/// @brief Matches a descriptor desc1 with an ensemble of descriptors desc2 based on KNN search strategy.
/// [in] desc1: source descriptor.
/// [in] desc2: target descriptors.
/// [out] matches: ensemble of detected matches, a pair of source/target indices.
///@return IDescriptorMatcher::RetCode::DESCRIPTORS_MATCHER_OK if succeed.
IDescriptorMatcher::RetCode match(
const SRef<datastructure::DescriptorBuffer> descriptors1,
const std::vector<SRef<datastructure::DescriptorBuffer>> & descriptors2,
Expand All @@ -92,7 +92,7 @@ class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherKNNOpencv : public org::bcom:
/// @param[in] frame The frame contains descriptors to match.
/// @param[out] matches A vector of matches representing pairs of indices relatively to the first and second set of descriptors.
/// @return DesciptorMatcher::DESCRIPTORS_MATCHER_OK if matching succeeds, DesciptorMatcher::DESCRIPTORS_DONT_MATCH if the types of descriptors are different, DesciptorMatcher::DESCRIPTOR_TYPE_UNDEFINED if one of the descriptors set is unknown, or DesciptorMatcher::DESCRIPTOR_EMPTY if one of the set is empty.
virtual IDescriptorMatcher::RetCode matchInRegion(
IDescriptorMatcher::RetCode matchInRegion(
const std::vector<datastructure::Point2Df> & points2D,
const std::vector<SRef<datastructure::DescriptorBuffer>> & descriptors,
const SRef<datastructure::Frame> frame,
Expand All @@ -101,6 +101,21 @@ class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherKNNOpencv : public org::bcom:
const float matchingDistanceMax = 0.f
) override;

/// @brief Match each descriptor input with descriptors of a frame in a region. The searching space is a circle which is defined by a 2D center and a radius
/// @param[in] currentFrame the current frame.
/// @param[in] lastFrame the last frame.
/// @param[out] matches a vector of matches between two frames representing pairs of keypoint indices relatively.
/// @param[in] radius the radius of search region around each keypoint of the last frame.
/// @param[in] matchingDistanceMax the maximum distance to valid a match.
/// @return DesciptorMatcher::DESCRIPTORS_MATCHER_OK if matching succeeds, DesciptorMatcher::DESCRIPTORS_DONT_MATCH if the types of descriptors are different, DesciptorMatcher::DESCRIPTOR_TYPE_UNDEFINED if one of the descriptors set is unknown, or DesciptorMatcher::DESCRIPTOR_EMPTY if one of the set is empty.
IDescriptorMatcher::RetCode matchInRegion(
const SRef<datastructure::Frame> currentFrame,
const SRef<datastructure::Frame> lastFrame,
std::vector<datastructure::DescriptorMatch> &matches,
const float radius = 0.f,
const float matchingDistanceMax = 0.f
) override;


private:

Expand All @@ -116,11 +131,6 @@ class SOLAROPENCV_EXPORT_API SolARDescriptorMatcherKNNOpencv : public org::bcom:
int m_id;
cv::FlannBasedMatcher m_matcher;

IDescriptorMatcher::RetCode match(
SRef<datastructure::DescriptorBuffer>& descriptors1,
SRef<datastructure::DescriptorBuffer>& descriptors2,
std::vector<std::vector< cv::DMatch >>& matches,int nbOfMatches);

};

}
Expand Down
3 changes: 3 additions & 0 deletions interfaces/SolARKeypointDetectorOpencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ class SOLAROPENCV_EXPORT_API SolARKeypointDetectorOpencv : public org::bcom::xpc
int m_id;
cv::Ptr<cv::Feature2D> m_detector;
cv::KeyPointsFilter kptsFilter;
int m_nbGridWidth = 20;
int m_nbGridHeight = 20;
float m_borderRatio = 0.01f;

};

Expand Down
5 changes: 5 additions & 0 deletions interfaces/SolARModuleOpencv_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class SolARUndistortPointsOpencv;
class SolARVideoAsCameraOpencv;
class SolARDeviceDataLoader;
class SolARMapFusionOpencv;
class SolARCornerRefinementOpencv;
}
}
}
Expand Down Expand Up @@ -324,5 +325,9 @@ XPCF_DEFINE_COMPONENT_TRAITS(SolAR::MODULES::OPENCV::SolARMapFusionOpencv,
"bc661909-0185-40a4-a5e6-e52280e7b338",
"SolARMapFusionOpencv",
"Merge local map or floating map in the global map.")
XPCF_DEFINE_COMPONENT_TRAITS(SolAR::MODULES::OPENCV::SolARCornerRefinementOpencv,
"ddae46ca-1657-4301-a87d-f2dcfa6265d0",
"SolARCornerRefinementOpencv",
"Refine the corner locations.")

#endif // SOLARMODULEOPENCV_TRAITS_H
29 changes: 20 additions & 9 deletions interfaces/SolARUndistortPointsOpencv.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@

#ifndef SOLARUNDISTORTPOINTS_H
#define SOLARUNDISTORTPOINTS_H
#include <vector>

#include "xpcf/component/ComponentBase.h"
#include "SolAROpencvAPI.h"
#include "api/geom/IUndistortPoints.h"

#include "opencv2/core.hpp"

#include "SolAROpencvAPI.h"
#include <vector>

namespace SolAR {
namespace MODULES {
Expand All @@ -45,12 +42,26 @@ class SOLAROPENCV_EXPORT_API SolARUndistortPointsOpencv : public org::bcom::xpcf
~SolARUndistortPointsOpencv() = default;

void unloadComponent () override final;
FrameworkReturnCode undistort(const std::vector<datastructure::Point2Df> & inputPoints, std::vector<datastructure::Point2Df> & outputPoints) override;

/// @brief Set the distortion intrinsic camera parameters
void setDistortionParameters(const datastructure::CamDistortion & distortion_parameters) override;
/// @brief Set the intrinsic camera parameters
void setIntrinsicParameters(const datastructure::CamCalibration & intrinsic_parameters) override;
/// @brief This method corrects undistortsion to a set of 2D points
/// @param[in] inputPoints the set of 2D points to correct
/// @param[out] outputPoints the undistorted 2D Points
/// @return FrameworkReturnCode::_SUCCESS_ if 2D transformation succeed, else FrameworkReturnCode::_ERROR.
FrameworkReturnCode undistort(const std::vector<datastructure::Point2Df> & inputPoints,
std::vector<datastructure::Point2Df> & outputPoints) override;

/// @brief This method corrects undistortsion to a set of 2D keypoints
/// @param[in] inputKeypoints the set of 2D keypoints to correct
/// @param[out] outputKeypoints the undistorted 2D keypoints
/// @return FrameworkReturnCode::_SUCCESS_ if 2D transformation succeed, else FrameworkReturnCode::_ERROR.
FrameworkReturnCode undistort(const std::vector<datastructure::Keypoint> & inputKeypoints,
std::vector<datastructure::Keypoint> & outputKeypoints) override;

/// @brief this method is used to set intrinsic parameters and distorsion of the camera
/// @param[in] Camera calibration matrix parameters.
/// @param[in] Camera distorsion parameters.
void setCameraParameters(const datastructure::CamCalibration & intrinsicParams,
const datastructure::CamDistortion & distorsionParams) override;


private:
Expand Down
2 changes: 1 addition & 1 deletion packagedependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SolARFramework|0.9.0|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download
SolARFramework|0.9.1|SolARFramework|SolARBuild@github|https://github.com/SolarFramework/SolarFramework/releases/download
29 changes: 27 additions & 2 deletions src/SolARCameraOpencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,33 @@ namespace OPENCV {
LOG_INFO("Camera using {} * {} resolution", m_parameters.resolution.width ,m_parameters.resolution.height)
if (m_is_resolution_set)
{
m_capture.set(cv::CAP_PROP_FRAME_WIDTH, m_parameters.resolution.width );
m_capture.set(cv::CAP_PROP_FRAME_HEIGHT, m_parameters.resolution.height );
bool setResolutionFailed = false;

auto setResolution = [&]
(cv::VideoCaptureProperties dimensionProp,
uint32_t value,
const std::string& dimensionName)
{
bool setResDimOk = m_capture.set(dimensionProp, value);

if (!setResDimOk || m_capture.get(dimensionProp) != value)
{
setResolutionFailed = true;
LOG_ERROR("Cannot set camera {} to {}", dimensionName, value);
if (!setResDimOk)
{
LOG_WARNING( "Note: cv::VideoCapture::set() returned 'true'");
}
}
};

setResolution(cv::CAP_PROP_FRAME_WIDTH, m_parameters.resolution.width, "width");
setResolution(cv::CAP_PROP_FRAME_HEIGHT, m_parameters.resolution.height, "height");

if ( setResolutionFailed )
{
return FrameworkReturnCode::_ERROR_;
}
}
else {
// set default resolution : get camera resolution ? or force camera resolution from default resolution values ?
Expand Down
77 changes: 77 additions & 0 deletions src/SolARCornerRefinementOpencv.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/**
* @copyright Copyright (c) 2017 B-com http://www.b-com.com/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "SolARCornerRefinementOpencv.h"
#include "SolARImageConvertorOpencv.h"
#include "SolAROpenCVHelper.h"
#include "core/Log.h"
#include <opencv2/imgproc.hpp>
namespace xpcf = org::bcom::xpcf;

XPCF_DEFINE_FACTORY_CREATE_INSTANCE(SolAR::MODULES::OPENCV::SolARCornerRefinementOpencv)

namespace SolAR {
using namespace datastructure;
namespace MODULES {
namespace OPENCV {

SolARCornerRefinementOpencv::SolARCornerRefinementOpencv() :ConfigurableBase(xpcf::toUUID<SolARCornerRefinementOpencv>())
{
declareInterface<api::features::ICornerRefinement>(this);
declareProperty("nbMaxIters", m_nbMaxIters);
declareProperty("minAccuracy", m_minAccuracy);
declareProperty("winSize", m_winSize);
LOG_DEBUG(" SolARFiducialMarkerPoseEstimatorOpencv constructor")
}

xpcf::XPCFErrorCode SolARCornerRefinementOpencv::onConfigured()
{
m_termcrit = cv::TermCriteria(cv::TermCriteria::COUNT | cv::TermCriteria::EPS, m_nbMaxIters, m_minAccuracy);
m_subPixWinSize = cv::Size(m_winSize, m_winSize);
LOG_DEBUG(" SolARCornerRefinementOpencv configured");
return xpcf::XPCFErrorCode::_SUCCESS;
}

void SolARCornerRefinementOpencv::refine(const SRef<datastructure::Image> image, std::vector<datastructure::Point2Df>& corners)
{
// transform all SolAR data to openCv data
SRef<Image> convertedImage = image;
if (image->getImageLayout() != Image::ImageLayout::LAYOUT_GREY) {
// input Image not in grey levels : convert it !
SolARImageConvertorOpencv convertor;
convertedImage = xpcf::utils::make_shared<Image>(Image::ImageLayout::LAYOUT_GREY, Image::PixelOrder::INTERLEAVED, image->getDataType());
convertor.convert(image, convertedImage);
}
cv::Mat imageOpencv;
SolAROpenCVHelper::mapToOpenCV(convertedImage, imageOpencv);

std::vector<cv::Point2f> cornersOpencv;
for (const auto &cor : corners)
cornersOpencv.push_back(cv::Point2f(cor.getX(), cor.getY()));

// refine
cv::cornerSubPix(imageOpencv, cornersOpencv, m_subPixWinSize, cv::Size(-1, -1), m_termcrit);

// return output
corners.clear();
for (const auto &cor : cornersOpencv)
corners.push_back(datastructure::Point2Df(cor.x, cor.y));
}

}
}
}

Loading

0 comments on commit e812dbf

Please sign in to comment.