diff --git a/CMakeLists.txt b/CMakeLists.txt index f05adb32daef2a102b9486b18307ba5e4afa61b6..bdb8245844b3995532b16e691524a1c83a0cae19 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -290,12 +290,10 @@ OCV_OPTION(WITH_HALIDE "Include Halide support" OFF OCV_OPTION(WITH_VULKAN "Include Vulkan support" OFF VISIBLE_IF TRUE VERIFY HAVE_VULKAN) -OCV_OPTION(WITH_INF_ENGINE "Include Intel Inference Engine support" OFF +# replacement for deprecated options: WITH_INF_ENGINE, WITH_NGRAPH +OCV_OPTION(WITH_OPENVINO "Include Intel OpenVINO toolkit support" (WITH_INF_ENGINE) VISIBLE_IF TRUE - VERIFY INF_ENGINE_TARGET) -OCV_OPTION(WITH_NGRAPH "Include nGraph support" WITH_INF_ENGINE - VISIBLE_IF TRUE - VERIFY TARGET ngraph::ngraph) + VERIFY TARGET ocv.3rdparty.openvino) OCV_OPTION(WITH_WEBNN "Include WebNN support" OFF VISIBLE_IF TRUE VERIFY HAVE_WEBNN) @@ -802,7 +800,7 @@ if(WITH_WEBNN) endif() # --- Inference Engine --- -if(WITH_INF_ENGINE) +if(WITH_INF_ENGINE OR WITH_OPENVINO) include(cmake/OpenCVDetectInferenceEngine.cmake) endif() @@ -1537,55 +1535,61 @@ if(WITH_HALIDE OR HAVE_HALIDE) status(" Halide:" HAVE_HALIDE THEN "YES (${HALIDE_LIBRARIES} ${HALIDE_INCLUDE_DIRS})" ELSE NO) endif() -if(WITH_INF_ENGINE OR INF_ENGINE_TARGET) - if(INF_ENGINE_TARGET) - list(GET INF_ENGINE_TARGET 0 ie_target) - set(__msg "YES (${INF_ENGINE_RELEASE} / ${INF_ENGINE_VERSION})") - ocv_get_imported_target(ie_target "${ie_target}") - get_target_property(_lib ${ie_target} IMPORTED_LOCATION) - get_target_property(_lib_imp_rel ${ie_target} IMPORTED_IMPLIB_RELEASE) - get_target_property(_lib_imp_dbg ${ie_target} IMPORTED_IMPLIB_DEBUG) - get_target_property(_lib_rel ${ie_target} IMPORTED_LOCATION_RELEASE) - get_target_property(_lib_dbg ${ie_target} IMPORTED_LOCATION_DEBUG) - ocv_build_features_string(_lib - IF _lib THEN "${_lib}" - IF _lib_imp_rel AND _lib_imp_dbg THEN "${_lib_imp_rel} / ${_lib_imp_dbg}" - IF _lib_rel AND _lib_dbg THEN "${_lib_rel} / ${_lib_dbg}" - IF _lib_rel THEN "${_lib_rel}" - IF _lib_dbg THEN "${_lib_dbg}" - ELSE "unknown" - ) - get_target_property(_inc ${ie_target} INTERFACE_INCLUDE_DIRECTORIES) - status(" Inference Engine:" "${__msg}") - status(" * libs:" "${_lib}") - status(" * includes:" "${_inc}") - else() - status(" Inference Engine:" "NO") +if(HAVE_OPENVINO + OR (WITH_OPENVINO AND NOT WITH_INF_ENGINE AND NOT INF_ENGINE_TARGET) +) + status(" OpenVINO:" TARGET openvino::runtime THEN "YES (${OpenVINO_VERSION})" ELSE "NO") +else() + if(WITH_INF_ENGINE OR INF_ENGINE_TARGET) + if(INF_ENGINE_TARGET) + list(GET INF_ENGINE_TARGET 0 ie_target) + set(__msg "YES (${INF_ENGINE_RELEASE} / ${INF_ENGINE_VERSION})") + ocv_get_imported_target(ie_target "${ie_target}") + get_target_property(_lib ${ie_target} IMPORTED_LOCATION) + get_target_property(_lib_imp_rel ${ie_target} IMPORTED_IMPLIB_RELEASE) + get_target_property(_lib_imp_dbg ${ie_target} IMPORTED_IMPLIB_DEBUG) + get_target_property(_lib_rel ${ie_target} IMPORTED_LOCATION_RELEASE) + get_target_property(_lib_dbg ${ie_target} IMPORTED_LOCATION_DEBUG) + ocv_build_features_string(_lib + IF _lib THEN "${_lib}" + IF _lib_imp_rel AND _lib_imp_dbg THEN "${_lib_imp_rel} / ${_lib_imp_dbg}" + IF _lib_rel AND _lib_dbg THEN "${_lib_rel} / ${_lib_dbg}" + IF _lib_rel THEN "${_lib_rel}" + IF _lib_dbg THEN "${_lib_dbg}" + ELSE "unknown" + ) + get_target_property(_inc ${ie_target} INTERFACE_INCLUDE_DIRECTORIES) + status(" Inference Engine:" "${__msg}") + status(" * libs:" "${_lib}") + status(" * includes:" "${_inc}") + else() + status(" Inference Engine:" "NO") + endif() endif() -endif() -if(WITH_NGRAPH OR HAVE_NGRAPH) - if(HAVE_NGRAPH) - ocv_get_imported_target(__target ngraph::ngraph) - set(__msg "YES (${ngraph_VERSION})") - get_target_property(_lib ${__target} IMPORTED_LOCATION) - get_target_property(_lib_imp_rel ${__target} IMPORTED_IMPLIB_RELEASE) - get_target_property(_lib_imp_dbg ${__target} IMPORTED_IMPLIB_DEBUG) - get_target_property(_lib_rel ${__target} IMPORTED_LOCATION_RELEASE) - get_target_property(_lib_dbg ${__target} IMPORTED_LOCATION_DEBUG) - ocv_build_features_string(_lib - IF _lib THEN "${_lib}" - IF _lib_imp_rel AND _lib_imp_dbg THEN "${_lib_imp_rel} / ${_lib_imp_dbg}" - IF _lib_rel AND _lib_dbg THEN "${_lib_rel} / ${_lib_dbg}" - IF _lib_rel THEN "${_lib_rel}" - IF _lib_dbg THEN "${_lib_dbg}" - ELSE "unknown" - ) - get_target_property(_inc ${__target} INTERFACE_INCLUDE_DIRECTORIES) - status(" nGraph:" "${__msg}") - status(" * libs:" "${_lib}") - status(" * includes:" "${_inc}") - else() - status(" nGraph:" "NO") + if(WITH_NGRAPH OR HAVE_NGRAPH) + if(HAVE_NGRAPH) + ocv_get_imported_target(__target ngraph::ngraph) + set(__msg "YES (${ngraph_VERSION})") + get_target_property(_lib ${__target} IMPORTED_LOCATION) + get_target_property(_lib_imp_rel ${__target} IMPORTED_IMPLIB_RELEASE) + get_target_property(_lib_imp_dbg ${__target} IMPORTED_IMPLIB_DEBUG) + get_target_property(_lib_rel ${__target} IMPORTED_LOCATION_RELEASE) + get_target_property(_lib_dbg ${__target} IMPORTED_LOCATION_DEBUG) + ocv_build_features_string(_lib + IF _lib THEN "${_lib}" + IF _lib_imp_rel AND _lib_imp_dbg THEN "${_lib_imp_rel} / ${_lib_imp_dbg}" + IF _lib_rel AND _lib_dbg THEN "${_lib_rel} / ${_lib_dbg}" + IF _lib_rel THEN "${_lib_rel}" + IF _lib_dbg THEN "${_lib_dbg}" + ELSE "unknown" + ) + get_target_property(_inc ${__target} INTERFACE_INCLUDE_DIRECTORIES) + status(" nGraph:" "${__msg}") + status(" * libs:" "${_lib}") + status(" * includes:" "${_inc}") + else() + status(" nGraph:" "NO") + endif() endif() endif() diff --git a/cmake/OpenCVDetectInferenceEngine.cmake b/cmake/OpenCVDetectInferenceEngine.cmake index 6521fbab93159e0750cc4913aa4c5627850408cc..f9b0dd672b0be4ed96408dccc4894710283733fc 100644 --- a/cmake/OpenCVDetectInferenceEngine.cmake +++ b/cmake/OpenCVDetectInferenceEngine.cmake @@ -1,22 +1,20 @@ -# The script detects Intel(R) Inference Engine installation -# -# Cache variables: -# INF_ENGINE_RELEASE - a number reflecting IE source interface (linked with OpenVINO release) -# -# Detect parameters: -# 1. Native cmake IE package: -# - environment variable InferenceEngine_DIR is set to location of cmake module -# 2. Custom location: -# - INF_ENGINE_INCLUDE_DIRS - headers search location -# - INF_ENGINE_LIB_DIRS - library search location -# 3. OpenVINO location: -# - environment variable INTEL_OPENVINO_DIR is set to location of OpenVINO installation dir -# - INF_ENGINE_PLATFORM - part of name of library directory representing its platform +# The script detects Intel(R) OpenVINO(TM) runtime installation # # Result: -# INF_ENGINE_TARGET - set to name of imported library target representing InferenceEngine -# +# - target ocv.3rdparty.openvino +if(WITH_OPENVINO) + find_package(OpenVINO QUIET) + if(OpenVINO_FOUND) + message(STATUS "OpenVINO FOUND: ${OpenVINO_VERSION}") + math(EXPR ver "${OpenVINO_VERSION_MAJOR} * 1000000 + ${OpenVINO_VERSION_MINOR} * 10000 + ${OpenVINO_VERSION_PATCH} * 100") + ocv_add_external_target(openvino "" "openvino::runtime" "INF_ENGINE_RELEASE=${ver};HAVE_NGRAPH;HAVE_DNN_NGRAPH;HAVE_INF_ENGINE") + set(HAVE_OPENVINO 1) + return() + endif() +endif() + +# ====================== macro(ocv_ie_find_extra_libraries find_prefix find_suffix) file(GLOB libraries "${INF_ENGINE_LIB_DIRS}/${find_prefix}inference_engine*${find_suffix}") @@ -145,15 +143,19 @@ if(NOT INF_ENGINE_TARGET AND _loc) add_custom_ie_build("${ie_custom_env_inc}" "${ie_custom_env_lib}" "${ie_custom_env_lib_rel}" "${ie_custom_env_lib_dbg}" "OpenVINO (${_loc})") endif() -# Add more features to the target +set(tgts) +set(defs) +# Add more features to the target if(INF_ENGINE_TARGET) set_target_properties(${INF_ENGINE_TARGET} PROPERTIES INTERFACE_COMPILE_DEFINITIONS "HAVE_INF_ENGINE=1;INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}" ) + list(APPEND tgts ${INF_ENGINE_TARGET}) + list(APPEND defs "INF_ENGINE_RELEASE=${INF_ENGINE_RELEASE}" "HAVE_INF_ENGINE") endif() -if(WITH_NGRAPH) +if(WITH_NGRAPH OR NOT DEFINED WITH_NGRAPH) find_package(ngraph QUIET) if(ngraph_FOUND) ocv_assert(TARGET ngraph::ngraph) @@ -162,5 +164,9 @@ if(WITH_NGRAPH) endif() message(STATUS "Detected ngraph: cmake package (${ngraph_VERSION})") set(HAVE_NGRAPH ON) + list(APPEND tgts ngraph::ngraph) + list(APPEND defs "HAVE_NGRAPH" "HAVE_DNN_NGRAPH") endif() endif() + +ocv_add_external_target(openvino "" "${tgts}" "${defs}") diff --git a/doc/tutorials/introduction/config_reference/config_reference.markdown b/doc/tutorials/introduction/config_reference/config_reference.markdown index dda14108c442c1fb2cfea4b4dfbd8fecd84b7658..388b0cc7c1e1edb74c4bb4a0d65db970db16d434 100644 --- a/doc/tutorials/introduction/config_reference/config_reference.markdown +++ b/doc/tutorials/introduction/config_reference/config_reference.markdown @@ -476,9 +476,10 @@ OpenCV have own DNN inference module which have own build-in engine, but can als | `BUILD_PROTOBUF` | _ON_ | Build own copy of _protobuf_. Must be disabled if you want to use external library. | | `PROTOBUF_UPDATE_FILES` | _OFF_ | Re-generate all .proto files. _protoc_ compiler compatible with used version of _protobuf_ must be installed. | | `OPENCV_DNN_OPENCL` | _ON_ | Enable built-in OpenCL inference backend. | -| `WITH_INF_ENGINE` | _OFF_ | Enables [Intel Inference Engine (IE)](https://github.com/openvinotoolkit/openvino) backend. Allows to execute networks in IE format (.xml + .bin). Inference Engine must be installed either as part of [OpenVINO toolkit](https://en.wikipedia.org/wiki/OpenVINO), either as a standalone library built from sources. | -| `INF_ENGINE_RELEASE` | _2020040000_ | Defines version of Inference Engine library which is tied to OpenVINO toolkit version. Must be a 10-digit string, e.g. _2020040000_ for OpenVINO 2020.4. | -| `WITH_NGRAPH` | _OFF_ | Enables Intel NGraph library support. This library is part of Inference Engine backend which allows executing arbitrary networks read from files in multiple formats supported by OpenCV: Caffe, TensorFlow, PyTorch, Darknet, etc.. NGraph library must be installed, it is included into Inference Engine. | +| `WITH_INF_ENGINE` | _OFF_ | **Deprecated since OpenVINO 2022.1** Enables [Intel Inference Engine (IE)](https://github.com/openvinotoolkit/openvino) backend. Allows to execute networks in IE format (.xml + .bin). Inference Engine must be installed either as part of [OpenVINO toolkit](https://en.wikipedia.org/wiki/OpenVINO), either as a standalone library built from sources. | +| `INF_ENGINE_RELEASE` | _2020040000_ | **Deprecated since OpenVINO 2022.1** Defines version of Inference Engine library which is tied to OpenVINO toolkit version. Must be a 10-digit string, e.g. _2020040000_ for OpenVINO 2020.4. | +| `WITH_NGRAPH` | _OFF_ | **Deprecated since OpenVINO 2022.1** Enables Intel NGraph library support. This library is part of Inference Engine backend which allows executing arbitrary networks read from files in multiple formats supported by OpenCV: Caffe, TensorFlow, PyTorch, Darknet, etc.. NGraph library must be installed, it is included into Inference Engine. | +| `WITH_OPENVINO` | _OFF_ | Enable Intel OpenVINO Toolkit support. Should be used for OpenVINO>=2022.1 instead of `WITH_INF_ENGINE` and `WITH_NGRAPH`. | | `OPENCV_DNN_CUDA` | _OFF_ | Enable CUDA backend. [CUDA](https://en.wikipedia.org/wiki/CUDA), CUBLAS and [CUDNN](https://developer.nvidia.com/cudnn) must be installed. | | `WITH_HALIDE` | _OFF_ | Use experimental [Halide](https://en.wikipedia.org/wiki/Halide_(programming_language)) backend which can generate optimized code for dnn-layers at runtime. Halide must be installed. | | `WITH_VULKAN` | _OFF_ | Enable experimental [Vulkan](https://en.wikipedia.org/wiki/Vulkan_(API)) backend. Does not require additional dependencies, but can use external Vulkan headers (`VULKAN_INCLUDE_DIRS`). | diff --git a/modules/dnn/CMakeLists.txt b/modules/dnn/CMakeLists.txt index dfc08e8b9bdf776eb077549220053ab5d0a2fb77..cc29d092f4eb1e1fbb7339ec63b4f928e9bc4464 100644 --- a/modules/dnn/CMakeLists.txt +++ b/modules/dnn/CMakeLists.txt @@ -165,24 +165,8 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") endif() set(dnn_runtime_libs "") -if(INF_ENGINE_TARGET) - set(use_nn_builder OFF) - if(TARGET inference_engine_nn_builder OR # custom imported target - TARGET IE::inference_engine_nn_builder OR # default imported target via InferenceEngineConfig.cmake - INF_ENGINE_RELEASE VERSION_LESS "2020000000") # compatibility with older versions on IE - set(use_nn_builder ON) - endif() - ocv_option(OPENCV_DNN_IE_NN_BUILDER_2019 "Build with Inference Engine NN Builder API support" ${use_nn_builder}) # future: NOT HAVE_NGRAPH - if(OPENCV_DNN_IE_NN_BUILDER_2019) - message(STATUS "DNN: Enabling Inference Engine NN Builder API support") - add_definitions(-DHAVE_DNN_IE_NN_BUILDER_2019=1) - endif() - list(APPEND dnn_runtime_libs ${INF_ENGINE_TARGET}) -endif() -if(HAVE_NGRAPH) - message(STATUS "DNN: Enabling Inference Engine nGraph API support") - add_definitions(-DHAVE_DNN_NGRAPH) - list(APPEND dnn_runtime_libs ngraph::ngraph) +if(TARGET ocv.3rdparty.openvino) + list(APPEND dnn_runtime_libs ocv.3rdparty.openvino) endif() ocv_glob_module_sources(${sources_options} SOURCES ${fw_srcs} ${webnn_srcs}) @@ -193,7 +177,7 @@ ocv_add_accuracy_tests(${dnn_runtime_libs}) set(perf_path "${CMAKE_CURRENT_LIST_DIR}/perf") file(GLOB_RECURSE perf_srcs "${perf_path}/*.cpp") file(GLOB_RECURSE perf_hdrs "${perf_path}/*.hpp" "${perf_path}/*.h") -ocv_add_perf_tests(${INF_ENGINE_TARGET} +ocv_add_perf_tests(${dnn_runtime_libs} FILES test_common "${CMAKE_CURRENT_LIST_DIR}/test/test_common.hpp" "${CMAKE_CURRENT_LIST_DIR}/test/test_common.impl.hpp" FILES Src ${perf_srcs} FILES Include ${perf_hdrs} diff --git a/modules/gapi/CMakeLists.txt b/modules/gapi/CMakeLists.txt index 98ce66ded9eeb138cf79fb0fba9a1125fdacb095..dd135d1efc1b6b9809ff6b26a3d931236ade53cc 100644 --- a/modules/gapi/CMakeLists.txt +++ b/modules/gapi/CMakeLists.txt @@ -13,8 +13,14 @@ if(NOT TARGET ade) return() endif() -if(INF_ENGINE_TARGET) - ocv_option(OPENCV_GAPI_INF_ENGINE "Build GraphAPI module with Inference Engine support" ON) +if(TARGET ocv.3rdparty.openvino) + # TODO: remove OPENCV_GAPI_INF_ENGINE option + set(initial_value ON) + if(DEFINED OPENCV_GAPI_INF_ENGINE) + set(initial_value ${OPENCV_GAPI_INF_ENGINE}) + message(WARNING "OPENCV_GAPI_INF_ENGINE option is deprecated. Use OPENCV_GAPI_WITH_OPENVINO option instead.") + endif() + ocv_option(OPENCV_GAPI_WITH_OPENVINO "G-API: Enable OpenVINO Toolkit support" ${initial_value}) endif() set(the_description "OpenCV G-API Core Module") @@ -228,12 +234,8 @@ ocv_create_module() ocv_target_link_libraries(${the_module} PRIVATE ade) -if(OPENCV_GAPI_INF_ENGINE) - ocv_target_link_libraries(${the_module} PRIVATE ${INF_ENGINE_TARGET}) -endif() - -if (HAVE_NGRAPH) - ocv_target_link_libraries(${the_module} PRIVATE ngraph::ngraph) +if(TARGET ocv.3rdparty.openvino AND OPENCV_GAPI_WITH_OPENVINO) + ocv_target_link_libraries(${the_module} PRIVATE ocv.3rdparty.openvino) endif() if(HAVE_TBB) @@ -248,11 +250,8 @@ if(CV_TRACE AND HAVE_ITT) endif() set(__test_extra_deps "") -if(OPENCV_GAPI_INF_ENGINE) - list(APPEND __test_extra_deps ${INF_ENGINE_TARGET}) -endif() -if(HAVE_NGRAPH) - list(APPEND __test_extra_deps ngraph::ngraph) +if(TARGET ocv.3rdparty.openvino AND OPENCV_GAPI_WITH_OPENVINO) + list(APPEND __test_extra_deps ocv.3rdparty.openvino) endif() ocv_add_accuracy_tests(${__test_extra_deps}) @@ -263,9 +262,6 @@ ocv_add_accuracy_tests(${__test_extra_deps}) if(TARGET opencv_test_gapi) target_include_directories(opencv_test_gapi PRIVATE "${CMAKE_CURRENT_LIST_DIR}/src") target_link_libraries(opencv_test_gapi PRIVATE ade) - if (HAVE_NGRAPH) - ocv_target_compile_definitions(opencv_test_gapi PRIVATE -DHAVE_NGRAPH) - endif() endif() if(HAVE_TBB AND TARGET opencv_test_gapi) @@ -347,9 +343,8 @@ ocv_add_samples() # Required for sample with inference on host if(TARGET example_gapi_onevpl_infer_single_roi) - if(OPENCV_GAPI_INF_ENGINE) - ocv_target_link_libraries(example_gapi_onevpl_infer_single_roi PRIVATE ${INF_ENGINE_TARGET}) - ocv_target_compile_definitions(example_gapi_onevpl_infer_single_roi PRIVATE -DHAVE_INF_ENGINE) + if(TARGET ocv.3rdparty.openvino AND OPENCV_GAPI_WITH_OPENVINO) + ocv_target_link_libraries(example_gapi_onevpl_infer_single_roi PRIVATE ocv.3rdparty.openvino) endif() if(HAVE_D3D11 AND HAVE_OPENCL) ocv_target_include_directories(example_gapi_onevpl_infer_single_roi SYSTEM PRIVATE ${OPENCL_INCLUDE_DIRS})