summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Bermond2018-11-26 13:26:55 +0000
committerDaniel Bermond2018-11-26 13:26:55 +0000
commit4fd54b7682feb836d48c2ed8f6d94810a7754a7c (patch)
tree055e46332cdf69b29d3d643008cbb40057acef3b
parent01a0e21e01233a13fd68f44f0f5cdedff4731caf (diff)
downloadaur-4fd54b7682feb836d48c2ed8f6d94810a7754a7c.tar.gz
Fix build with opencv4
-rw-r--r--.SRCINFO6
-rw-r--r--Makefile.config2
-rw-r--r--PKGBUILD12
-rw-r--r--caffe-1.0-opencv4-fix.patch116
4 files changed, 130 insertions, 6 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 2e0e9d553d6a..76214f9d403d 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = caffe
pkgdesc = A deep learning framework made with expression, speed, and modularity in mind (cpu only)
pkgver = 1.0
- pkgrel = 13
+ pkgrel = 14
url = https://caffe.berkeleyvision.org/
arch = i686
arch = x86_64
@@ -43,8 +43,10 @@ pkgbase = caffe
replaces = caffe-cpu
source = caffe-1.0.tar.gz::https://github.com/BVLC/caffe/archive/1.0.tar.gz
source = Makefile.config
+ source = caffe-1.0-opencv4-fix.patch
sha256sums = 71d3c9eb8a183150f965a465824d01fe82826c22505f7aa314f700ace03fa77f
- sha256sums = dfa45f0d358b75c28049602d68d6468478c39d45518d584290af76d4ef74738e
+ sha256sums = 78137e80f764f51c0d4eeed5ce566f3745614b572b481c50197199291d34e2cd
+ sha256sums = 2072c8ca1393b53ef280a15c43af940cc9bf1419ae32b3d8a6541b10b8cb50e9
pkgname = caffe
diff --git a/Makefile.config b/Makefile.config
index 3b8fd75b2012..9a7b0d741472 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -1,6 +1,6 @@
_PYVER := $(shell python -c 'import sys; print("%s.%s" %sys.version_info[0:2])')
_PYMAJ := $(shell python -c 'import sys; print("%s" %sys.version_info[0])')
-_OCVMAJ := $(shell opencv_version | awk -F'.' '{ print $1 }')
+_OCVMAJ := $(shell opencv_version | awk -F'.' '{ print $$1 }')
CPU_ONLY := 1
USE_OPENCV := 1
diff --git a/PKGBUILD b/PKGBUILD
index a3b1f9207345..2287dbd63a49 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -3,7 +3,7 @@
pkgname=caffe
pkgver=1.0
-pkgrel=13
+pkgrel=14
pkgdesc='A deep learning framework made with expression, speed, and modularity in mind (cpu only)'
arch=('i686' 'x86_64')
url='https://caffe.berkeleyvision.org/'
@@ -27,12 +27,18 @@ provides=('caffe-cpu')
conflicts=('caffe-cpu')
replaces=('caffe-cpu')
source=("${pkgname}-${pkgver}.tar.gz"::"https://github.com/BVLC/caffe/archive/${pkgver}.tar.gz"
- 'Makefile.config')
+ 'Makefile.config'
+ 'caffe-1.0-opencv4-fix.patch')
sha256sums=('71d3c9eb8a183150f965a465824d01fe82826c22505f7aa314f700ace03fa77f'
- 'dfa45f0d358b75c28049602d68d6468478c39d45518d584290af76d4ef74738e')
+ '78137e80f764f51c0d4eeed5ce566f3745614b572b481c50197199291d34e2cd'
+ '2072c8ca1393b53ef280a15c43af940cc9bf1419ae32b3d8a6541b10b8cb50e9')
prepare() {
cp -af "${srcdir}/Makefile.config" "${srcdir}/${pkgname}-${pkgver}"
+
+ # fix build with opencv 4.0
+ cd "${pkgname}-${pkgver}"
+ patch -Np1 -i "${srcdir}/caffe-1.0-opencv4-fix.patch"
}
build() {
diff --git a/caffe-1.0-opencv4-fix.patch b/caffe-1.0-opencv4-fix.patch
new file mode 100644
index 000000000000..1aef32f2eabc
--- /dev/null
+++ b/caffe-1.0-opencv4-fix.patch
@@ -0,0 +1,116 @@
+From 7f503bd9a19758a173064e299ab9d4cac65ed60f Mon Sep 17 00:00:00 2001
+From: Daniel Bermond <danielbermond@gmail.com>
+Date: Mon, 26 Nov 2018 13:11:23 +0000
+Subject: [PATCH] Fix build with OpenCV 4.0
+
+---
+ Makefile | 16 ++++++++++++++--
+ Makefile.config.example | 2 +-
+ src/caffe/layers/window_data_layer.cpp | 2 +-
+ src/caffe/test/test_io.cpp | 4 ++--
+ src/caffe/util/io.cpp | 8 ++++----
+ 5 files changed, 22 insertions(+), 10 deletions(-)
+
+diff --git a/Makefile b/Makefile
+index b7660e852d6..95f3443adab 100644
+--- a/Makefile
++++ b/Makefile
+@@ -200,9 +200,17 @@ endif
+ ifeq ($(USE_OPENCV), 1)
+ LIBRARIES += opencv_core opencv_highgui opencv_imgproc
+
+- ifeq ($(OPENCV_VERSION), 3)
++ ifeq ($(OPENCV_VERSION), $(filter $(OPENCV_VERSION), 3 4))
+ LIBRARIES += opencv_imgcodecs
+ endif
++ ifeq ($(OPENCV_VERSION), 4)
++ ifeq ($(USE_PKG_CONFIG), 1)
++ INCLUDE_DIRS += $(shell pkg-config opencv4 --cflags-only-I | sed 's/-I//g')
++ else
++ INCLUDE_DIRS += /usr/include/opencv4 /usr/local/include/opencv4
++ INCLUDE_DIRS += /usr/include/opencv4/opencv /usr/local/include/opencv4/opencv
++ endif
++ endif
+
+ endif
+ PYTHON_LIBRARIES ?= boost_python python2.7
+@@ -429,7 +437,11 @@ LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
+
+ USE_PKG_CONFIG ?= 0
+ ifeq ($(USE_PKG_CONFIG), 1)
+- PKG_CONFIG := $(shell pkg-config opencv --libs)
++ ifeq ($(OPENCV_VERSION), 4)
++ PKG_CONFIG := $(shell pkg-config opencv4 --libs)
++ else
++ PKG_CONFIG := $(shell pkg-config opencv --libs)
++ endif
+ else
+ PKG_CONFIG :=
+ endif
+diff --git a/Makefile.config.example b/Makefile.config.example
+index 24ca632783a..24802e91534 100644
+--- a/Makefile.config.example
++++ b/Makefile.config.example
+@@ -19,7 +19,7 @@
+ # possibility of simultaneous read and write
+ # ALLOW_LMDB_NOLOCK := 1
+
+-# Uncomment if you're using OpenCV 3
++# Uncomment and set accordingly if you're using OpenCV 3/4
+ # OPENCV_VERSION := 3
+
+ # To customize your choice of compiler, uncomment and set the following.
+diff --git a/src/caffe/layers/window_data_layer.cpp b/src/caffe/layers/window_data_layer.cpp
+index 1bf3760e9fd..f41169debe4 100644
+--- a/src/caffe/layers/window_data_layer.cpp
++++ b/src/caffe/layers/window_data_layer.cpp
+@@ -290,7 +290,7 @@ void WindowDataLayer<Dtype>::load_batch(Batch<Dtype>* batch) {
+ image_database_cache_[window[WindowDataLayer<Dtype>::IMAGE_INDEX]];
+ cv_img = DecodeDatumToCVMat(image_cached.second, true);
+ } else {
+- cv_img = cv::imread(image.first, CV_LOAD_IMAGE_COLOR);
++ cv_img = cv::imread(image.first, cv::IMREAD_COLOR);
+ if (!cv_img.data) {
+ LOG(ERROR) << "Could not open or find file " << image.first;
+ return;
+diff --git a/src/caffe/test/test_io.cpp b/src/caffe/test/test_io.cpp
+index c2c919e90dc..b80df287fba 100644
+--- a/src/caffe/test/test_io.cpp
++++ b/src/caffe/test/test_io.cpp
+@@ -20,8 +20,8 @@ class IOTest : public ::testing::Test {};
+ bool ReadImageToDatumReference(const string& filename, const int label,
+ const int height, const int width, const bool is_color, Datum* datum) {
+ cv::Mat cv_img;
+- int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
+- CV_LOAD_IMAGE_GRAYSCALE);
++ int cv_read_flag = (is_color ? cv::IMREAD_COLOR :
++ cv::IMREAD_GRAYSCALE);
+
+ cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
+ if (!cv_img_origin.data) {
+diff --git a/src/caffe/util/io.cpp b/src/caffe/util/io.cpp
+index 5295d9dddb9..1f9167a114f 100644
+--- a/src/caffe/util/io.cpp
++++ b/src/caffe/util/io.cpp
+@@ -73,8 +73,8 @@ void WriteProtoToBinaryFile(const Message& proto, const char* filename) {
+ cv::Mat ReadImageToCVMat(const string& filename,
+ const int height, const int width, const bool is_color) {
+ cv::Mat cv_img;
+- int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
+- CV_LOAD_IMAGE_GRAYSCALE);
++ int cv_read_flag = (is_color ? cv::IMREAD_COLOR :
++ cv::IMREAD_GRAYSCALE);
+ cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
+ if (!cv_img_origin.data) {
+ LOG(ERROR) << "Could not open or find file " << filename;
+@@ -179,8 +179,8 @@ cv::Mat DecodeDatumToCVMat(const Datum& datum, bool is_color) {
+ CHECK(datum.encoded()) << "Datum not encoded";
+ const string& data = datum.data();
+ std::vector<char> vec_data(data.c_str(), data.c_str() + data.size());
+- int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
+- CV_LOAD_IMAGE_GRAYSCALE);
++ int cv_read_flag = (is_color ? cv::IMREAD_COLOR :
++ cv::IMREAD_GRAYSCALE);
+ cv_img = cv::imdecode(vec_data, cv_read_flag);
+ if (!cv_img.data) {
+ LOG(ERROR) << "Could not decode datum ";