Skip to content

Commit

Permalink
opencv: added openvino support
Browse files Browse the repository at this point in the history
  • Loading branch information
ilya-lavrenov committed Nov 17, 2023
1 parent 28d8a49 commit 9791355
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions recipes/opencv/4.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ patches:
patch_description: "MinGW: disable obsensor to avoid build issue"
patch_type: "portability"
patch_source: "https://github.com/opencv/opencv/pull/24478"
- patch_file: "patches/4.8.1-0003-openvino-cmake-fix.patch"
patch_description: "Fixed issue with OpenVINO and static build"
patch_type: "portability"
patch_source: "https://github.com/opencv/opencv/pull/23963"
"4.5.5":
- patch_file: "patches/4.5.5-0001-find-openexr.patch"
patch_description: "Robust discovery & injection of OpenEXR"
Expand Down
21 changes: 19 additions & 2 deletions recipes/opencv/4.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class OpenCVConan(ConanFile):
"with_flatbuffers": [True, False],
"with_protobuf": [True, False],
"with_vulkan": [True, False],
"with_openvino": [True, False],
"dnn_cuda": [True, False],
# highgui module options
"with_gtk": [True, False],
Expand Down Expand Up @@ -181,6 +182,7 @@ class OpenCVConan(ConanFile):
"with_flatbuffers": True,
"with_protobuf": True,
"with_vulkan": False,
"with_openvino": False,
"dnn_cuda": False,
# highgui module options
"with_gtk": False,
Expand Down Expand Up @@ -276,6 +278,10 @@ def _has_wechat_qrcode_option(self):
def _has_barcode_option(self):
return Version(self.version) >= "4.5.3" and Version(self.version) < "4.8.0"

@property
def _has_openvino_option(self):
return Version(self.version) >= "4.6.0"

@property
def _has_with_wayland_option(self):
return Version(self.version) >= "4.7.0" and self.settings.os in ["Linux", "FreeBSD"]
Expand Down Expand Up @@ -422,6 +428,9 @@ def wayland():
def xkbcommon():
return ["xkbcommon::libxkbcommon"] if self.options.get_safe("with_wayland") else []

def openvino():
return ["openvino::Runtime"] if self.options.get_safe("with_openvino") else []

def opencv_calib3d():
return ["opencv_calib3d"] if self.options.calib3d else []

Expand Down Expand Up @@ -496,7 +505,7 @@ def opencv_xfeatures2d():
"dnn": {
"is_built": self.options.dnn,
"mandatory_options": ["imgproc"],
"requires": ["opencv_core", "opencv_imgproc"] + protobuf() + vulkan() + ipp(),
"requires": ["opencv_core", "opencv_imgproc"] + protobuf() + vulkan() + ipp() + openvino(),
},
"features2d": {
"is_built": self.options.features2d,
Expand Down Expand Up @@ -1030,11 +1039,15 @@ def configure(self):
# Call this first before any further manipulation of options based on other options
self._solve_internal_dependency_graph(self._opencv_modules)

if not self._has_openvino_option:
self.options.rm_safe("with_openvino")

if not self.options.dnn:
self.options.rm_safe("dnn_cuda")
self.options.rm_safe("with_flatbuffers")
self.options.rm_safe("with_protobuf")
self.options.rm_safe("with_vulkan")
self.options.rm_safe("with_openvino")
if not self.options.highgui:
self.options.rm_safe("with_gtk")
self.options.rm_safe("with_wayland")
Expand Down Expand Up @@ -1094,6 +1107,8 @@ def requirements(self):
self.requires("protobuf/3.21.12", transitive_libs=True)
if self.options.get_safe("with_vulkan"):
self.requires("vulkan-headers/1.3.268.0")
if self.options.get_safe("with_openvino"):
self.requires("openvino/2023.2.0")
# gapi module dependencies
if self.options.gapi:
self.requires("ade/0.1.2d")
Expand Down Expand Up @@ -1475,8 +1490,10 @@ def generate(self):

tc.variables["OPENCV_DNN_CUDA"] = self.options.get_safe("dnn_cuda", False)

if self._has_openvino_option:
tc.variables["WITH_OPENVINO"] = self.options.get_safe("with_openvino", False)

if Version(self.version) >= "4.6.0":
tc.variables["WITH_OPENVINO"] = False
tc.variables["WITH_TIMVX"] = False
else:
tc.variables["WITH_INF_ENGINE"] = False
Expand Down
23 changes: 23 additions & 0 deletions recipes/opencv/4.x/patches/4.8.1-0003-openvino-cmake-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--- a/cmake/OpenCVUtils.cmake
+++ b/cmake/OpenCVUtils.cmake
@@ -1632,13 +1632,19 @@ function(ocv_add_external_target name inc link def)
endif()
endfunction()

+set(__OPENCV_EXPORTED_EXTERNAL_TARGETS "" CACHE INTERNAL "")
function(ocv_install_used_external_targets)
if(NOT BUILD_SHARED_LIBS
AND NOT (CMAKE_VERSION VERSION_LESS "3.13.0") # upgrade CMake: https://gitlab.kitware.com/cmake/cmake/-/merge_requests/2152
)
foreach(tgt in ${ARGN})
if(tgt MATCHES "^ocv\.3rdparty\.")
- install(TARGETS ${tgt} EXPORT OpenCVModules)
+ list(FIND __OPENCV_EXPORTED_EXTERNAL_TARGETS "${tgt}" _found)
+ if(_found EQUAL -1) # don't export target twice
+ install(TARGETS ${tgt} EXPORT OpenCVModules)
+ list(APPEND __OPENCV_EXPORTED_EXTERNAL_TARGETS "${tgt}")
+ set(__OPENCV_EXPORTED_EXTERNAL_TARGETS "${__OPENCV_EXPORTED_EXTERNAL_TARGETS}" CACHE INTERNAL "")
+ endif()
endif()
endforeach()
endif()

0 comments on commit 9791355

Please sign in to comment.