Skip to content

Commit

Permalink
Merge pull request opencv#17133 from alalek:build_fix_gapi_ie
Browse files Browse the repository at this point in the history
  • Loading branch information
alalek committed Apr 22, 2020
2 parents 561421f + 351fb8c commit a1641f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
15 changes: 13 additions & 2 deletions modules/gapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if(NOT TARGET ade)
return()
endif()

if(INF_ENGINE_TARGET)
ocv_option(OPENCV_GAPI_INF_ENGINE "Build GraphAPI module with Inference Engine support" ON)
endif()

set(the_description "OpenCV G-API Core Module")

ocv_add_module(gapi
Expand Down Expand Up @@ -139,12 +143,19 @@ ocv_module_include_directories("${CMAKE_CURRENT_LIST_DIR}/src")

ocv_create_module()

ocv_target_link_libraries(${the_module} PRIVATE ade ${INF_ENGINE_TARGET})
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_TBB)
ocv_target_link_libraries(${the_module} PRIVATE tbb)
endif()

ocv_add_accuracy_tests(${INF_ENGINE_TARGET})
set(__test_extra_deps "")
if(OPENCV_GAPI_INF_ENGINE)
list(APPEND __test_extra_deps ${INF_ENGINE_TARGET})
endif()
ocv_add_accuracy_tests(${__test_extra_deps})
# FIXME: test binary is linked with ADE directly since ADE symbols
# are not exported from libopencv_gapi.so in any form - thus
# there're two copies of ADE code in memory when tests run (!)
Expand Down
8 changes: 6 additions & 2 deletions modules/gapi/include/opencv2/gapi/own/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,27 @@ namespace cv
return result;
}

cv::gapi::own::Mat to_own(Mat&&) = delete;
cv::gapi::own::Mat to_own(Mat&&) = delete;

inline cv::gapi::own::Mat to_own(Mat const& m) {
return (m.dims == 2)
? cv::gapi::own::Mat{m.rows, m.cols, m.type(), m.data, m.step}
: cv::gapi::own::Mat{to_own<int>(m.size), m.type(), m.data};
};

namespace gapi
{
namespace own
{

inline cv::Mat to_ocv(Mat const& m) {
return m.dims.empty()
? cv::Mat{m.rows, m.cols, m.type(), m.data, m.step}
: cv::Mat{m.dims, m.type(), m.data};
}
cv::Mat to_ocv(Mat&&) = delete;

cv::Mat to_ocv(Mat&&) = delete;

} // namespace own
} // namespace gapi
} // namespace cv
Expand Down
9 changes: 6 additions & 3 deletions modules/gapi/src/backends/ie/giebackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <opencv2/gapi/util/any.hpp>
#include <opencv2/gapi/gtype_traits.hpp>
#include <opencv2/gapi/infer.hpp>
#include <opencv2/gapi/own/convert.hpp>

#include "compiler/gobjref.hpp"
#include "compiler/gmodel.hpp"
Expand Down Expand Up @@ -211,6 +212,7 @@ struct IEUnit {
cv::gimpl::ie::IECompiled compile() const {
auto this_plugin = IE::PluginDispatcher().getPluginByDevice(params.device_id);

#if INF_ENGINE_RELEASE < 2020000000 // <= 2019.R3
// Load extensions (taken from DNN module)
if (params.device_id == "CPU" || params.device_id == "FPGA")
{
Expand Down Expand Up @@ -247,10 +249,11 @@ struct IEUnit {
}
catch(...)
{
CV_LOG_WARNING(NULL, "Failed to load IE extension " << extlib);
CV_LOG_INFO(NULL, "Failed to load IE extension: " << extlib);
}
}
}
#endif

auto this_network = this_plugin.LoadNetwork(net, {}); // FIXME: 2nd parameter to be
// configurable via the API
Expand Down Expand Up @@ -514,7 +517,7 @@ struct Infer: public cv::detail::KernelTag {
// and redirect our data producers to this memory
// (A memory dialog comes to the picture again)

const cv::Mat this_mat = to_ocv(ctx.inMat(i));
const cv::Mat this_mat = ctx.inMat(i);
// FIXME: By default here we trait our inputs as images.
// May be we need to make some more intelligence here about it
IE::Blob::Ptr this_blob = wrapIE(this_mat, cv::gapi::ie::TraitAs::IMAGE);
Expand Down Expand Up @@ -586,7 +589,7 @@ struct InferList: public cv::detail::KernelTag {
GAPI_Assert(uu.params.num_in == 1); // roi list is not counted in net's inputs

const auto& in_roi_vec = ctx.inArg<cv::detail::VectorRef>(0u).rref<cv::Rect>();
const cv::Mat this_mat = to_ocv(ctx.inMat(1u));
const cv::Mat this_mat = ctx.inMat(1u);
// Since we do a ROI list inference, always assume our input buffer is image
IE::Blob::Ptr this_blob = wrapIE(this_mat, cv::gapi::ie::TraitAs::IMAGE);

Expand Down

0 comments on commit a1641f9

Please sign in to comment.