Skip to content

xfeatures2d: disable BoostDesc/VGG in case of missing data #2820

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

Merged
merged 1 commit 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
36 changes: 28 additions & 8 deletions modules/xfeatures2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@ 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)

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)
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()

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

ocv_module_include_directories("${DOWNLOAD_DIR}")
if(TARGET opencv_test_${name})
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()
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 @@ -1114,13 +1114,16 @@ TEST( Features2d_DescriptorExtractor_LATCH, 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 @@ -1176,7 +1179,7 @@ TEST( Features2d_DescriptorExtractor_BINBOOST_256, regression )
BoostDesc::create(BoostDesc::BINBOOST_256) );
test.safe_run();
}

#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA

/*#if CV_SSE2
TEST( Features2d_DescriptorExtractor_Calonder_uchar, regression )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ TEST(DISABLED_Features2d_RotationInvariance_Descriptor_DAISY, regression)
test.safe_run();
}

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
TEST(Features2d_RotationInvariance_Descriptor_VGG120, regression)
{
DescriptorRotationInvarianceTest test(KAZE::create(),
Expand Down Expand Up @@ -676,6 +677,7 @@ TEST(Features2d_RotationInvariance_Descriptor_VGG48, regression)
0.98f);
test.safe_run();
}
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

#ifdef OPENCV_ENABLE_NONFREE
TEST(Features2d_RotationInvariance_Descriptor_BRIEF_64, regression)
Expand Down Expand Up @@ -715,6 +717,7 @@ TEST(Features2d_RotationInvariance_Descriptor_FREAK, regression)
test.safe_run();
}

#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BGM, regression)
{
DescriptorRotationInvarianceTest test(SURF::create(),
Expand Down Expand Up @@ -777,6 +780,7 @@ TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BINBOOST_256, regression
0.98f);
test.safe_run();
}
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA

/*
* Detector's scale invariance check
Expand Down Expand Up @@ -840,6 +844,7 @@ TEST(DISABLED_Features2d_ScaleInvariance_Descriptor_DAISY, regression)
test.safe_run();
}

#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
TEST(Features2d_ScaleInvariance_Descriptor_VGG120, regression)
{
DescriptorScaleInvarianceTest test(KAZE::create(),
Expand Down Expand Up @@ -875,8 +880,10 @@ TEST(Features2d_ScaleInvariance_Descriptor_VGG48, regression)
0.93f);
test.safe_run();
}
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA

#ifdef OPENCV_ENABLE_NONFREE
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BGM, regression)
{
DescriptorScaleInvarianceTest test(SURF::create(),
Expand Down Expand Up @@ -939,6 +946,7 @@ TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BINBOOST_256, regression)
0.98f);
test.safe_run();
}
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
#endif // NONFREE

}} // namespace