meta-digi/meta-digi-dey/recipes-graphics/opencv/opencv/0001-dnn-allow-to-use-exter...

67 lines
2.4 KiB
Diff

From f1604999632344f5bcbf6f611693917f6a9c2aa3 Mon Sep 17 00:00:00 2001
From: Alexander Alekhin <alexander.alekhin@intel.com>
Date: Mon, 9 Jul 2018 17:19:35 +0300
Subject: [PATCH] dnn: allow to use external protobuf
"custom layers" feature will not work properly in these builds.
Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com>
Upstream-Status: Backport [https://github.com/opencv/opencv/commit/e2b5d112909b9dfd764f14833b82e38e4bc2f81f]
---
modules/dnn/CMakeLists.txt | 4 ++++
modules/dnn/src/caffe/caffe_io.cpp | 4 ++++
modules/dnn/test/test_layers.cpp | 4 ++++
3 files changed, 12 insertions(+)
diff --git a/modules/dnn/CMakeLists.txt b/modules/dnn/CMakeLists.txt
index e306dde..a2f741c 100644
--- a/modules/dnn/CMakeLists.txt
+++ b/modules/dnn/CMakeLists.txt
@@ -48,6 +48,10 @@ if(ANDROID)
add_definitions(-DDISABLE_POSIX_MEMALIGN -DTH_DISABLE_HEAP_TRACKING)
endif()
+if(NOT BUILD_PROTOBUF)
+ add_definitions(-DOPENCV_DNN_EXTERNAL_PROTOBUF=1)
+endif()
+
add_definitions(-DHAVE_PROTOBUF=1)
#suppress warnings in autogenerated caffe.pb.* files
diff --git a/modules/dnn/src/caffe/caffe_io.cpp b/modules/dnn/src/caffe/caffe_io.cpp
index 730c752..9f4e31c 100644
--- a/modules/dnn/src/caffe/caffe_io.cpp
+++ b/modules/dnn/src/caffe/caffe_io.cpp
@@ -1120,7 +1120,11 @@ bool ReadProtoFromTextFile(const char* filename, Message* proto) {
std::ifstream fs(filename, std::ifstream::in);
CHECK(fs.is_open()) << "Can't open \"" << filename << "\"";
IstreamInputStream input(&fs);
+#ifndef OPENCV_DNN_EXTERNAL_PROTOBUF
return google::protobuf::TextFormat::Parser(true).Parse(&input, proto);
+#else
+ return google::protobuf::TextFormat::Parser().Parse(&input, proto);
+#endif
}
bool ReadProtoFromBinaryFile(const char* filename, Message* proto) {
diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp
index 963206b..05ea61a 100644
--- a/modules/dnn/test/test_layers.cpp
+++ b/modules/dnn/test/test_layers.cpp
@@ -1150,7 +1150,11 @@ private:
TEST(Layer_Test_Interp_custom, Accuracy)
{
+#ifndef OPENCV_DNN_EXTERNAL_PROTOBUF
CV_DNN_REGISTER_LAYER_CLASS(Interp, InterpLayer);
+#else
+ CV_DNN_REGISTER_LAYER_CLASS(DISABLED_Interp, InterpLayer); // requires patched protobuf (available in OpenCV source tree only)
+#endif
testLayerUsingCaffeModels("layer_interp", DNN_TARGET_CPU, false, false);
LayerFactory::unregisterLayer("Interp");
}
--
2.7.4