BVLC/caffe

Can not compile with opencv3 on Mac at the latest version

Closed this issue ยท 8 comments

In makefile.config, I enabled opencv3

git log
commit be163be0ea5befada208dbf0db29e6fa5811dc86
Merge: 6ed3b2a a53fa51
Author: Evan Shelhamer <shelhamer@imaginarynumber.net>
Date:   Wed Mar 9 12:42:24 2016 -0800
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
caffe/$ make
PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
CXX src/caffe/blob.cpp
CXX src/caffe/common.cpp
CXX src/caffe/data_reader.cpp
CXX src/caffe/data_transformer.cpp
src/caffe/data_transformer.cpp:2:10: fatal error: 'opencv2/core/core.hpp' file not found
#include <opencv2/core/core.hpp>

Have you installed opencv3 with brew install opencv3?

Hi, yes, I install opencv3 by the command you mentioned, did you have the same problem?

No problem here. Can you post your Makefile.config?

I cloned the latest caffe, and now it works

I solved this problem by add opencv path to INCLUDE_DIRS in Makefile.config.

Whatever else you find you need goes here.

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/Cellar/opencv3/3.1.0_3/include

On OS X with brew, you really should use :

INCLUDE_DIRS += $(shell brew --prefix)/include
LIBRARY_DIRS += $(shell brew --prefix)/lib

Like the comment said by @AsiamCn, base on this config, you also need add library direction to LIBRARY_DIR, the full config should be:

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/Cellar/opencv3/3.1.0_3/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/Cellar/opencv3/3.1.0_3/lib

kp421 commented

For me for some reason it only worked if I added opencv4 at the end of INCLUDE_DIRS

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/Cellar/opencv/4.1.2/include/opencv4
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/local/Cellar/opencv/4.1.2/lib