Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge 3.4 #2823

Merged
merged 3 commits into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions modules/xfeatures2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,34 @@ if(HAVE_CUDA)
endif()
ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_shape opencv_ml opencv_cudaarithm WRAP python java objc)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
if(NOT boost_status OR NOT vgg_status)
ocv_module_disable(xfeatures2d)
endif()
if(NOT OPENCV_SKIP_FEATURES2D_DOWNLOADING)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
if(boost_status)
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/boostdesc.cpp "OPENCV_XFEATURES2D_HAS_BOOST_DATA=1")
else()
message(WARNING "features2d: Boost descriptor implementation is not available due to missing data (download failed: https://github.com/opencv/opencv_contrib/issues/1301)")
endif()
if(vgg_status)
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/vgg.cpp "OPENCV_XFEATURES2D_HAS_VGG_DATA=1")
else()
message(WARNING "features2d: VGG descriptor implementation is not available due to missing data (download failed: https://github.com/opencv/opencv_contrib/issues/1301)")
endif()

ocv_module_include_directories("${DOWNLOAD_DIR}")
if(boost_status OR vgg_status)
ocv_module_include_directories("${DOWNLOAD_DIR}")
endif()
endif()

if(TARGET opencv_test_${name})
ocv_target_include_directories(opencv_test_${name} "${OpenCV_SOURCE_DIR}/modules") # use common files from features2d tests
if(boost_status)
ocv_target_compile_definitions(opencv_test_${name} PRIVATE "OPENCV_XFEATURES2D_HAS_BOOST_DATA=1")
endif()
if(vgg_status)
ocv_target_compile_definitions(opencv_test_${name} PRIVATE "OPENCV_XFEATURES2D_HAS_VGG_DATA=1")
endif()
endif()
4 changes: 4 additions & 0 deletions modules/xfeatures2d/perf/perf_vgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace opencv_test { namespace {

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA

typedef perf::TestBaseWithParam<std::string> vgg;

#define VGG_IMAGES \
Expand Down Expand Up @@ -32,4 +34,6 @@ PERF_TEST_P(vgg, extract, testing::Values(VGG_IMAGES))
SANITY_CHECK_NOTHING();
}

#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

}} // namespace
9 changes: 9 additions & 0 deletions modules/xfeatures2d/src/boostdesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace cv
namespace xfeatures2d
{

#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA

/*
!BoostDesc implementation
*/
Expand Down Expand Up @@ -729,9 +731,16 @@ BoostDesc_Impl::~BoostDesc_Impl()
{
}

#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA

Ptr<BoostDesc> BoostDesc::create( int desc, bool use_scale_orientation, float scale_factor )
{
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
return makePtr<BoostDesc_Impl>( desc, use_scale_orientation, scale_factor );
#else
CV_UNUSED(desc); CV_UNUSED(use_scale_orientation); CV_UNUSED(scale_factor);
CV_Error(Error::StsNotImplemented, "The OpenCV xfeatures2d binaries is built without downloaded Boost decriptor features: https://github.com/opencv/opencv_contrib/issues/1301");
#endif
}


Expand Down
10 changes: 10 additions & 0 deletions modules/xfeatures2d/src/vgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ namespace cv
namespace xfeatures2d
{

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA

/*
!VGG implementation
*/
Expand Down Expand Up @@ -527,10 +529,18 @@ VGG_Impl::~VGG_Impl()
{
}

#endif

Ptr<VGG> VGG::create( int desc, float isigma, bool img_normalize, bool use_scale_orientation,
float scale_factor, bool dsc_normalize )
{
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
return makePtr<VGG_Impl>( desc, isigma, img_normalize, use_scale_orientation, scale_factor, dsc_normalize );
#else
CV_UNUSED(desc); CV_UNUSED(isigma); CV_UNUSED(img_normalize);
CV_UNUSED(use_scale_orientation); CV_UNUSED(scale_factor); CV_UNUSED(dsc_normalize);
CV_Error(Error::StsNotImplemented, "The OpenCV xfeatures2d binaries is built without downloaded VGG decriptor features: https://github.com/opencv/opencv_contrib/issues/1301");
#endif
}


Expand Down
5 changes: 4 additions & 1 deletion modules/xfeatures2d/test/test_features2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,16 @@ TEST(Features2d_DescriptorExtractor_BEBLID, regression )
test.safe_run();
}

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
TEST( Features2d_DescriptorExtractor_VGG, regression )
{
CV_DescriptorExtractorTest<L2<float> > test( "descriptor-vgg", 0.03f,
VGG::create() );
test.safe_run();
}
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
TEST( Features2d_DescriptorExtractor_BGM, regression )
{
CV_DescriptorExtractorTest<Hamming> test( "descriptor-boostdesc-bgm",
Expand Down Expand Up @@ -254,7 +257,7 @@ TEST( Features2d_DescriptorExtractor_BINBOOST_256, regression )
BoostDesc::create(BoostDesc::BINBOOST_256) );
test.safe_run();
}

#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA

#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_BruteForceDescriptorMatcher_knnMatch, regression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ INSTANTIATE_TEST_CASE_P(DAISY, DescriptorRotationInvariance, Values(
DAISY::create(15, 3, 8, 8, DAISY::NRM_NONE, noArray(), true, true),
0.79f)
));
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
INSTANTIATE_TEST_CASE_P(VGG120, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
KAZE::create(),
Expand All @@ -64,7 +65,7 @@ INSTANTIATE_TEST_CASE_P(VGG48, DescriptorRotationInvariance, Values(
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
0.97f)
));

#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

#ifdef OPENCV_ENABLE_NONFREE

Expand Down Expand Up @@ -96,6 +97,7 @@ INSTANTIATE_TEST_CASE_P(FREAK, DescriptorRotationInvariance, Values(
0.90f)
));

#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorRotationInvariance, Values(
make_tuple(IMAGE_TSUKUBA,
SURF::create(),
Expand Down Expand Up @@ -144,6 +146,7 @@ INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorRotationInvariance, Va
BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
0.999f)
));
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
#endif


Expand All @@ -170,6 +173,7 @@ INSTANTIATE_TEST_CASE_P(DISABLED_DAISY, DescriptorScaleInvariance, Values(
));
#endif

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
INSTANTIATE_TEST_CASE_P(VGG120, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
KAZE::create(),
Expand All @@ -194,8 +198,10 @@ INSTANTIATE_TEST_CASE_P(VGG48, DescriptorScaleInvariance, Values(
VGG::create(VGG::VGG_48, 1.4f, true, true, 48.0f, false),
0.93f)
));
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

#ifdef OPENCV_ENABLE_NONFREE // SURF detector is used in tests
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
INSTANTIATE_TEST_CASE_P(BoostDesc_BGM, DescriptorScaleInvariance, Values(
make_tuple(IMAGE_BIKES,
SURF::create(),
Expand Down Expand Up @@ -238,6 +244,7 @@ INSTANTIATE_TEST_CASE_P(BoostDesc_BINBOOST_256, DescriptorScaleInvariance, Value
BoostDesc::create(BoostDesc::BINBOOST_256, true, 6.25f),
0.98f)
));
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
#endif // NONFREE


Expand Down