Skip to content

Commit ebf745e

Browse files
committed
xfeatures2d: disable BoostDesc/VGG in case of missing data
1 parent d601d89 commit ebf745e

File tree

5 files changed

+59
-9
lines changed

5 files changed

+59
-9
lines changed

modules/xfeatures2d/CMakeLists.txt

+28-8
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,33 @@ if(HAVE_CUDA)
55
endif()
66
ocv_define_module(xfeatures2d opencv_core opencv_imgproc opencv_features2d opencv_calib3d OPTIONAL opencv_shape opencv_ml opencv_cudaarithm WRAP python java)
77

8-
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
9-
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
10-
set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
11-
download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
12-
download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
13-
if(NOT boost_status OR NOT vgg_status)
14-
ocv_module_disable(xfeatures2d)
8+
if(NOT OPENCV_SKIP_FEATURES2D_DOWNLOADING)
9+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_vgg.cmake)
10+
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/download_boostdesc.cmake)
11+
set(DOWNLOAD_DIR "${OpenCV_BINARY_DIR}/downloads/xfeatures2d")
12+
download_boost_descriptors("${DOWNLOAD_DIR}" boost_status)
13+
download_vgg_descriptors("${DOWNLOAD_DIR}" vgg_status)
14+
if(boost_status)
15+
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/boostdesc.cpp "OPENCV_XFEATURES2D_HAS_BOOST_DATA=1")
16+
else()
17+
message(WARNING "features2d: Boost descriptor implementation is not available due to missing data (download failed: https://github.com/opencv/opencv_contrib/issues/1301)")
18+
endif()
19+
if(vgg_status)
20+
ocv_append_source_file_compile_definitions(${CMAKE_CURRENT_SOURCE_DIR}/src/vgg.cpp "OPENCV_XFEATURES2D_HAS_VGG_DATA=1")
21+
else()
22+
message(WARNING "features2d: VGG descriptor implementation is not available due to missing data (download failed: https://github.com/opencv/opencv_contrib/issues/1301)")
23+
endif()
24+
25+
if(boost_status OR vgg_status)
26+
ocv_module_include_directories("${DOWNLOAD_DIR}")
27+
endif()
1528
endif()
1629

17-
ocv_module_include_directories("${DOWNLOAD_DIR}")
30+
if(TARGET opencv_test_${name})
31+
if(boost_status)
32+
ocv_target_compile_definitions(opencv_test_${name} PRIVATE "OPENCV_XFEATURES2D_HAS_BOOST_DATA=1")
33+
endif()
34+
if(vgg_status)
35+
ocv_target_compile_definitions(opencv_test_${name} PRIVATE "OPENCV_XFEATURES2D_HAS_VGG_DATA=1")
36+
endif()
37+
endif()

modules/xfeatures2d/src/boostdesc.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ namespace cv
6565
namespace xfeatures2d
6666
{
6767

68+
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
69+
6870
/*
6971
!BoostDesc implementation
7072
*/
@@ -729,9 +731,16 @@ BoostDesc_Impl::~BoostDesc_Impl()
729731
{
730732
}
731733

734+
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
735+
732736
Ptr<BoostDesc> BoostDesc::create( int desc, bool use_scale_orientation, float scale_factor )
733737
{
738+
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
734739
return makePtr<BoostDesc_Impl>( desc, use_scale_orientation, scale_factor );
740+
#else
741+
CV_UNUSED(desc); CV_UNUSED(use_scale_orientation); CV_UNUSED(scale_factor);
742+
CV_Error(Error::StsNotImplemented, "The OpenCV xfeatures2d binaries is built without downloaded Boost decriptor features: https://github.com/opencv/opencv_contrib/issues/1301");
743+
#endif
735744
}
736745

737746

modules/xfeatures2d/src/vgg.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ namespace cv
6666
namespace xfeatures2d
6767
{
6868

69+
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
70+
6971
/*
7072
!VGG implementation
7173
*/
@@ -527,10 +529,18 @@ VGG_Impl::~VGG_Impl()
527529
{
528530
}
529531

532+
#endif
533+
530534
Ptr<VGG> VGG::create( int desc, float isigma, bool img_normalize, bool use_scale_orientation,
531535
float scale_factor, bool dsc_normalize )
532536
{
537+
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
533538
return makePtr<VGG_Impl>( desc, isigma, img_normalize, use_scale_orientation, scale_factor, dsc_normalize );
539+
#else
540+
CV_UNUSED(desc); CV_UNUSED(isigma); CV_UNUSED(img_normalize);
541+
CV_UNUSED(use_scale_orientation); CV_UNUSED(scale_factor); CV_UNUSED(dsc_normalize);
542+
CV_Error(Error::StsNotImplemented, "The OpenCV xfeatures2d binaries is built without downloaded VGG decriptor features: https://github.com/opencv/opencv_contrib/issues/1301");
543+
#endif
534544
}
535545

536546

modules/xfeatures2d/test/test_features2d.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,16 @@ TEST( Features2d_DescriptorExtractor_LATCH, regression )
11141114
test.safe_run();
11151115
}
11161116

1117+
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
11171118
TEST( Features2d_DescriptorExtractor_VGG, regression )
11181119
{
11191120
CV_DescriptorExtractorTest<L2<float> > test( "descriptor-vgg", 0.03f,
11201121
VGG::create() );
11211122
test.safe_run();
11221123
}
1124+
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA
11231125

1126+
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
11241127
TEST( Features2d_DescriptorExtractor_BGM, regression )
11251128
{
11261129
CV_DescriptorExtractorTest<Hamming> test( "descriptor-boostdesc-bgm",
@@ -1176,7 +1179,7 @@ TEST( Features2d_DescriptorExtractor_BINBOOST_256, regression )
11761179
BoostDesc::create(BoostDesc::BINBOOST_256) );
11771180
test.safe_run();
11781181
}
1179-
1182+
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
11801183

11811184
/*#if CV_SSE2
11821185
TEST( Features2d_DescriptorExtractor_Calonder_uchar, regression )

modules/xfeatures2d/test/test_rotation_and_scale_invariance.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ TEST(DISABLED_Features2d_RotationInvariance_Descriptor_DAISY, regression)
641641
test.safe_run();
642642
}
643643

644+
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
644645
TEST(Features2d_RotationInvariance_Descriptor_VGG120, regression)
645646
{
646647
DescriptorRotationInvarianceTest test(KAZE::create(),
@@ -676,6 +677,7 @@ TEST(Features2d_RotationInvariance_Descriptor_VGG48, regression)
676677
0.98f);
677678
test.safe_run();
678679
}
680+
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA
679681

680682
#ifdef OPENCV_ENABLE_NONFREE
681683
TEST(Features2d_RotationInvariance_Descriptor_BRIEF_64, regression)
@@ -715,6 +717,7 @@ TEST(Features2d_RotationInvariance_Descriptor_FREAK, regression)
715717
test.safe_run();
716718
}
717719

720+
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
718721
TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BGM, regression)
719722
{
720723
DescriptorRotationInvarianceTest test(SURF::create(),
@@ -777,6 +780,7 @@ TEST(Features2d_RotationInvariance_Descriptor_BoostDesc_BINBOOST_256, regression
777780
0.98f);
778781
test.safe_run();
779782
}
783+
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
780784

781785
/*
782786
* Detector's scale invariance check
@@ -840,6 +844,7 @@ TEST(DISABLED_Features2d_ScaleInvariance_Descriptor_DAISY, regression)
840844
test.safe_run();
841845
}
842846

847+
#ifdef OPENCV_XFEATURES2D_HAS_VGG_DATA
843848
TEST(Features2d_ScaleInvariance_Descriptor_VGG120, regression)
844849
{
845850
DescriptorScaleInvarianceTest test(KAZE::create(),
@@ -875,8 +880,10 @@ TEST(Features2d_ScaleInvariance_Descriptor_VGG48, regression)
875880
0.93f);
876881
test.safe_run();
877882
}
883+
#endif // OPENCV_XFEATURES2D_HAS_VGG_DATA
878884

879885
#ifdef OPENCV_ENABLE_NONFREE
886+
#ifdef OPENCV_XFEATURES2D_HAS_BOOST_DATA
880887
TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BGM, regression)
881888
{
882889
DescriptorScaleInvarianceTest test(SURF::create(),
@@ -939,6 +946,7 @@ TEST(Features2d_ScaleInvariance_Descriptor_BoostDesc_BINBOOST_256, regression)
939946
0.98f);
940947
test.safe_run();
941948
}
949+
#endif // OPENCV_XFEATURES2D_HAS_BOOST_DATA
942950
#endif // NONFREE
943951

944952
}} // namespace

0 commit comments

Comments
 (0)