Skip to content

Commit

Permalink
allow to build opencv_objdetect without dnn in 4.5.5
Browse files Browse the repository at this point in the history
It has been "fixed" upstream for OpenCV 4.6.0

It fixes few things in this recipe:
- avoid a bug where quirc is in requirements, but not required by any component in package_indo() when dnn is False
- a regression introduced by conan-io#11009. Indeed objdetect can be built without dnn in all OpenCV version before 4.5.4, so this PR was breaking these versions when dnn was False by not exposing opencv_objdetect and few contrib components.
  • Loading branch information
SpaceIm committed Jan 9, 2023
1 parent 947475f commit 6c93f60
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 11 deletions.
10 changes: 7 additions & 3 deletions recipes/opencv/4.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ patches:
- patch_file: "patches/4.5.5-0001-find-openexr.patch"
patch_description: "Robust discovery & injection of OpenEXR"
patch_type: "conan"
- patch_file: "patches/4.5.5-0002-objdetect-without-dnn.patch"
patch_description: "Allow to build objdetect module without dnn"
patch_type: "portability"
patch_source: "https://github.com/opencv/opencv/pull/21369"
- patch_file: "patches/4.5.5-0003-find-quirc.patch"
patch_description: "Robust discovery & injection of quirc"
patch_type: "conan"
- patch_file: "patches/4.5.0-0002-find-ade.patch"
patch_description: "Robust discovery & injection of ade"
patch_type: "conan"
- patch_file: "patches/4.1.2-0003-find-quirc.patch"
patch_description: "Robust discovery & injection of quirc"
patch_type: "conan"
"4.5.3":
- patch_file: "patches/4.5.3-0001-find-openexr.patch"
patch_description: "Robust discovery & injection of OpenEXR"
Expand Down
16 changes: 8 additions & 8 deletions recipes/opencv/4.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ def ipp():
else:
return []

def opencv_dnn():
return ["opencv_dnn"] if self.options.dnn else []

opencv_components = [
{"target": "opencv_core", "lib": "core", "requires": ["zlib::zlib"] + parallel() + eigen() + ipp()},
{"target": "opencv_flann", "lib": "flann", "requires": ["opencv_core"] + eigen() + ipp()},
Expand All @@ -613,6 +616,8 @@ def ipp():
+ eigen() + ffmpeg() + ipp())},
{"target": "opencv_calib3d", "lib": "calib3d", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d"]+ eigen() + ipp()},
{"target": "opencv_highgui", "lib": "highgui", "requires": ["opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_videoio"] + freetype() + eigen() + gtk() + ipp()},
{"target": "opencv_objdetect", "lib": "objdetect", "requires": ["opencv_core", "opencv_imgproc", "opencv_calib3d"] + eigen() + ipp() + quirc() +
opencv_dnn() if Version(self.version) >= "4.5.4" else []},
{"target": "opencv_stitching", "lib": "stitching", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_calib3d"] + xfeatures2d() + eigen() + ipp()},
{"target": "opencv_video", "lib": "video", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_calib3d"] + eigen() + ipp()},
]
Expand All @@ -624,8 +629,6 @@ def ipp():
if self.options.dnn:
opencv_components.extend([
{"target": "opencv_dnn", "lib": "dnn", "requires": ["opencv_core", "opencv_imgproc"] + protobuf() + ipp()},
{"target": "opencv_objdetect", "lib": "objdetect", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_calib3d"] + eigen() + quirc() + ipp()},

])
if self.options.contrib:
opencv_components.extend([
Expand All @@ -647,21 +650,18 @@ def ipp():
{"target": "opencv_videostab", "lib": "videostab", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_photo", "opencv_features2d", "opencv_imgcodecs", "opencv_videoio", "opencv_calib3d", "opencv_video"] + eigen() + ipp()},
{"target": "opencv_xfeatures2d", "lib": "xfeatures2d", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_ml", "opencv_features2d", "opencv_calib3d", "opencv_shape", ] + eigen() + ipp()},
{"target": "opencv_ximgproc", "lib": "ximgproc", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d", "opencv_video"] + eigen() + ipp()},
{"target": "opencv_xobjdetect", "lib": "xobjdetect", "requires": ["opencv_core", "opencv_imgproc", "opencv_objdetect", "opencv_imgcodecs"] + eigen() + ipp()},
{"target": "opencv_aruco", "lib": "aruco", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d"] + eigen() + ipp()},
{"target": "opencv_bgsegm", "lib": "bgsegm", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_calib3d", "opencv_video"] + eigen() + ipp()},
{"target": "opencv_bioinspired", "lib": "bioinspired", "requires": ["opencv_core", "opencv_imgproc", "opencv_imgcodecs", "opencv_videoio", "opencv_highgui"] + eigen() + ipp()},
{"target": "opencv_ccalib", "lib": "ccalib", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_videoio", "opencv_calib3d", "opencv_highgui"] + eigen() + ipp()},
{"target": "opencv_dpm", "lib": "dpm", "requires": ["opencv_core", "opencv_imgproc", "opencv_objdetect", "opencv_highgui"] + eigen() + ipp()},
{"target": "opencv_face", "lib": "face", "requires": ["opencv_core", "opencv_imgproc", "opencv_objdetect", "opencv_calib3d", "opencv_photo"] + eigen() + ipp()},
{"target": "opencv_optflow", "lib": "optflow", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_video", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d", "opencv_video", "opencv_ximgproc"] + eigen() + ipp()},
{"target": "opencv_superres", "lib": "superres", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_videoio", "opencv_calib3d", "opencv_video", "opencv_ximgproc", "opencv_optflow"] + eigen() + ipp()},
{"target": "opencv_tracking", "lib": "tracking", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_ml", "opencv_plot", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d", "opencv_datasets", "opencv_video"] + eigen() + ipp()},
{"target": "opencv_stereo", "lib": "stereo", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_ml", "opencv_plot", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d", "opencv_datasets", "opencv_video", "opencv_tracking"] + eigen() + ipp()},
])
if self.options.dnn:
opencv_components.extend([
{"target": "opencv_xobjdetect", "lib": "xobjdetect", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_calib3d", "opencv_objdetect"] + eigen() + ipp()},
{"target": "opencv_dpm", "lib": "dpm", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_features2d", "opencv_imgcodecs", "opencv_videoio", "opencv_calib3d", "opencv_highgui", "opencv_objdetect"] + eigen() + ipp()},
{"target": "opencv_face", "lib": "face", "requires": ["opencv_core", "opencv_flann", "opencv_imgproc", "opencv_photo", "opencv_features2d", "opencv_calib3d", "opencv_objdetect"] + eigen() + ipp()}
])
if self.version >= "4.3.0":
opencv_components.extend([
{"target": "opencv_intensity_transform", "lib": "intensity_transform", "requires": ["opencv_core", "opencv_imgproc"] + eigen() + ipp()},
Expand Down
97 changes: 97 additions & 0 deletions recipes/opencv/4.x/patches/4.5.5-0002-objdetect-without-dnn.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
--- a/modules/objdetect/CMakeLists.txt
+++ b/modules/objdetect/CMakeLists.txt
@@ -1,5 +1,16 @@
set(the_description "Object Detection")
-ocv_define_module(objdetect opencv_core opencv_imgproc opencv_calib3d opencv_dnn WRAP java objc python js)
+ocv_define_module(objdetect
+ opencv_core
+ opencv_imgproc
+ opencv_calib3d
+ OPTIONAL
+ opencv_dnn
+ WRAP
+ python
+ java
+ objc
+ js
+)

if(HAVE_QUIRC)
get_property(QUIRC_INCLUDE GLOBAL PROPERTY QUIRC_INCLUDE_DIR)
--- a/modules/objdetect/src/face_detect.cpp
+++ b/modules/objdetect/src/face_detect.cpp
@@ -6,13 +6,16 @@

#include "opencv2/imgproc.hpp"
#include "opencv2/core.hpp"
+#ifdef HAVE_OPENCV_DNN
#include "opencv2/dnn.hpp"
+#endif

#include <algorithm>

namespace cv
{

+#ifdef HAVE_OPENCV_DNN
class FaceDetectorYNImpl : public FaceDetectorYN
{
public:
@@ -273,6 +276,7 @@ class FaceDetectorYNImpl : public FaceDetectorYN

std::vector<Rect2f> priors;
};
+#endif

Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& model,
const String& config,
@@ -283,7 +287,12 @@ Ptr<FaceDetectorYN> FaceDetectorYN::create(const String& model,
const int backend_id,
const int target_id)
{
+#ifdef HAVE_OPENCV_DNN
return makePtr<FaceDetectorYNImpl>(model, config, input_size, score_threshold, nms_threshold, top_k, backend_id, target_id);
+#else
+ CV_UNUSED(model); CV_UNUSED(config); CV_UNUSED(input_size); CV_UNUSED(score_threshold); CV_UNUSED(nms_threshold); CV_UNUSED(top_k); CV_UNUSED(backend_id); CV_UNUSED(target_id);
+ CV_Error(cv::Error::StsNotImplemented, "cv::FaceDetectorYN requires enabled 'dnn' module.");
+#endif
}

} // namespace cv
--- a/modules/objdetect/src/face_recognize.cpp
+++ b/modules/objdetect/src/face_recognize.cpp
@@ -4,13 +4,17 @@

#include "precomp.hpp"

+#include "opencv2/core.hpp"
+#ifdef HAVE_OPENCV_DNN
#include "opencv2/dnn.hpp"
+#endif

#include <algorithm>

namespace cv
{

+#ifdef HAVE_OPENCV_DNN
class FaceRecognizerSFImpl : public FaceRecognizerSF
{
public:
@@ -173,10 +177,16 @@ class FaceRecognizerSFImpl : public FaceRecognizerSF
private:
dnn::Net net;
};
+#endif

Ptr<FaceRecognizerSF> FaceRecognizerSF::create(const String& model, const String& config, int backend_id, int target_id)
{
+#ifdef HAVE_OPENCV_DNN
return makePtr<FaceRecognizerSFImpl>(model, config, backend_id, target_id);
+#else
+ CV_UNUSED(model); CV_UNUSED(config); CV_UNUSED(backend_id); CV_UNUSED(target_id);
+ CV_Error(cv::Error::StsNotImplemented, "cv::FaceRecognizerSF requires enabled 'dnn' module");
+#endif
}

} // namespace cv
12 changes: 12 additions & 0 deletions recipes/opencv/4.x/patches/4.5.5-0003-find-quirc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/modules/objdetect/CMakeLists.txt
+++ b/modules/objdetect/CMakeLists.txt
@@ -13,7 +13,6 @@ ocv_define_module(objdetect
)

if(HAVE_QUIRC)
- get_property(QUIRC_INCLUDE GLOBAL PROPERTY QUIRC_INCLUDE_DIR)
- ocv_include_directories(${QUIRC_INCLUDE})
- ocv_target_link_libraries(${the_module} quirc)
+ find_package(quirc REQUIRED CONFIG)
+ ocv_target_link_libraries(${the_module} quirc::quirc)
endif()

0 comments on commit 6c93f60

Please sign in to comment.