libprotobuf is optional dependency now

pull/265/head
Vitaliy Lyudvichenko 10 years ago
parent eba62d5068
commit 383715d330
  1. 40
      modules/dnn/CMakeLists.txt
  2. 21
      modules/dnn/src/caffe_importer.cpp

@ -1,34 +1,38 @@
cmake_minimum_required(VERSION 2.8)
macro(_dnn_do_protobuf_actions)
option(WITH_PROTOBUF "Build with libprotobuf" ON)
macro(_dnn_find_protobuf)
if(NOT WITH_PROTOBUF)
message(FATAL_ERROR "libprotobuf is required for dnn module")
endif()
find_package( Protobuf REQUIRED )
find_package( Protobuf )
if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
if(${PROTOBUF_FOUND} AND EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
message(STATUS "Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
file(GLOB PROTO_FILES src/*.proto)
PROTOBUF_GENERATE_CPP(PROTO_HDRS PROTO_SRCS ${PROTO_FILES})
set(HAVE_PROTOBUF ON)
else()
message(FATAL_ERROR "Could not find PROTOBUF Compiler")
message(WARNING "PROTOBUF not found. Caffe import function will be disabled.")
set(HAVE_PROTOBUF OFF)
endif()
file(GLOB PROTO_FILES src/*.proto)
PROTOBUF_GENERATE_CPP(PROTO_HDRS PROTO_SRCS ${PROTO_FILES})
endmacro(_dnn_do_protobuf_actions)
endmacro(_dnn_find_protobuf)
if(BUILD_opencv_core)#it's build for OpenCV module
_dnn_do_protobuf_actions()
set(the_description "Deep neural network module. Allow load models and make forward pass")
if(BUILD_opencv_core)#build as OpenCV module
_dnn_find_protobuf()
set(the_description "Deep neural network module. It allows to load models and to make forward pass")
set(OPENCV_MODULE_IS_PART_OF_WORLD OFF)
ocv_add_module(dnn opencv_imgproc opencv_core opencv_highgui WRAP python matlab)
ocv_warnings_disable(CMAKE_CXX_FLAGS -Wno-shadow -Wno-parentheses)
if(HAVE_PROTOBUF)
add_definitions(-DHAVE_PROTOBUF 1)
ocv_glob_module_sources(${PROTO_SRCS} ${PROTO_HDRS})
ocv_source_group("Src\\protobuf" FILES ${PROTO_SRCS} ${PROTO_HDRS})
ocv_module_include_directories(${PROTOBUF_INCLUDE_DIR} include src/caffe)
else()
file(GLOB NON_CAFFE_SOURCES "src/*.cpp" "src/layers/*.cpp")
file(GLOB NON_CAFFE_HEADERS "src/*.hpp" "src/layers/*.hpp")
ocv_set_module_sources(HEADERS ${NON_CAFFE_HEADERS} SOURCES ${NON_CAFFE_SOURCES})
endif()
ocv_module_include_directories(include src/caffe ${PROTOBUF_INCLUDE_DIR})
ocv_create_module(${PROTOBUF_LIBRARIES})
@ -36,10 +40,10 @@ ocv_add_accuracy_tests()
ocv_add_perf_tests()
ocv_add_samples()
else()#it's standalone module (development purposes)
else()#build as standalone module (for development purposes)
project(dnn_standalone)
_dnn_do_protobuf_actions()
_dnn_find_protobuf()
find_package( OpenCV 3.0 REQUIRED )
file(GLOB_RECURSE MODULE_SOURCES "src/*.cpp")

@ -1,4 +1,8 @@
#include "opencv2/dnn.hpp"
#include "precomp.hpp"
using namespace cv;
using namespace cv::dnn;
#if HAVE_PROTOBUF
#include "caffe.pb.h"
#include <iostream>
@ -9,9 +13,6 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include "caffe/util/upgrade_proto.hpp"
using namespace cv;
using namespace cv::dnn;
using ::google::protobuf::RepeatedField;
using ::google::protobuf::RepeatedPtrField;
using ::google::protobuf::Message;
@ -242,4 +243,14 @@ namespace
Ptr<Importer> cv::dnn::createCaffeImporter(const String &prototxt, const String &caffeModel)
{
return Ptr<Importer>(new CaffeImporter(prototxt.c_str(), caffeModel.c_str()));
}
}
#else //HAVE_PROTOBUF
Ptr<Importer> cv::dnn::createCaffeImporter(const String &prototxt, const String &caffeModel)
{
CV_Error(cv::Error::StsNotImplemented, "libprotobuf required to import data from Caffe models");
return Ptr<Importer>();
}
#endif //HAVE_PROTOBUF
Loading…
Cancel
Save