Ask Your Question
1

Java wrappers for dnn module - missing protobuf headers?

asked 2017-06-03 09:25:38 -0600

jcrist gravatar image

Dear OpenCV team, need your help.

I'm trying to generate java wrappers for dnn module. I was able to overcome some of the issues but this one is really cumbersome. I get the following exception during compilation of java wrappers:

 In file included from /opencv/build/modules/java/gen/dnn.cpp:17:
/opencv_contrib/modules/dnn/misc/tensorflow/attr_value.pb.h:9:10: fatal error: 'google/protobuf/stubs/common.h' file not found
#include <google/protobuf/stubs/common.h>

It seems like the issue is somehow related to 3rdparty protobuf library, which is building from sources along with OpenCV (BUILD_PROTOBUF=ON). I can find the missing header in the folder /opencv/build/3rdparty/protobuf/protobuf-3.1.0/src/google/protobuf/stubs/common.h but this path seems to be non-visible for the compiler.

Please kindly advise what would be the correct approach to fix this problem.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2017-06-03 11:38:03 -0600

jcrist gravatar image

updated 2017-06-04 08:43:25 -0600

I've made some progress in resolving this issue but not sure if this is the right approach or not. Seems like the problem is related to the way how include paths are configured in CMake for java module. The following changes are leading to successful compilation:

In the file /opencv_contrib/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake, the following line:

set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_CPP_ROOT}/src")

is to be replaced with

set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_CPP_ROOT}/src" PARENT_SCOPE)

The purpose of this change is to make the PROTOBUF_INCLUDE_DIR variable visible for the CMake script in the main repository.

The next step is to locate the following line in the /opencv/modules/java/CMakeLists.txt:

ocv_module_include_directories("${OpenCV_SOURCE_DIR}/include")

and insert the following code below this line:

if(BUILD_PROTOBUF)
    message(STATUS "PROTOBUF_INCLUDE_DIR=${PROTOBUF_INCLUDE_DIR}")
    ocv_module_include_directories("${PROTOBUF_INCLUDE_DIR}")
endif()

After these changes java wrappers are generated successfully for dnn module.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-06-03 09:25:38 -0600

Seen: 473 times

Last updated: Jun 04 '17