Ask Your Question

Java wrappers for dnn module - missing protobuf headers?

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

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

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

jcrist gravatar image

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

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:


is to be replaced with


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:


and insert the following code below this line:


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

edit flag offensive delete link more

Question Tools

1 follower


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

Seen: 286 times

Last updated: Jun 04 '17