MacでOpenCV4をコンパイルできるようにする
前提
OS: macOS Mojave バージョン10.14
OpenCV: 4.0.1
コンパイラ: gcc
手順
まず依存物をインストールする。
code:memo
brew install opencv
brew install -v cmake
brew install gcc
code:memo.sh
mkdir <directory>
cd <directory>
# 何かしらのエディタで開く
nano opencv_sample.cpp
とりあえずコンパイルできることを確認するためのサンプルソースをコピペする。ソースは以下のリンクから拝借。
code:opencv_sample.cpp
int main(int argc, char* argv[])
{
cv::Mat m1 = (cv::Mat_<double>(3, 3) << 0, 1, 2, 3, 4, 5, 6, 7, 8);
cv::Mat e = cv::Mat::eye(3, 3, CV_64F);
cv::Mat res = m1 * e;
std::cout << res << std::endl;
return 0;
}
コンパイルするためのCMakeLists.txtを作る。
code:memo
# 何かしらのエディタで開く
nano CMakeLists.txt
下記をコピペ。
code:CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
add_definitions(-std=c++11)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage opencv_sample.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
使用されるg++バージョンの確認。ここで古いg++がでてきたら後の工程でシンボリックリンクを作成しないといけない。
code:memo
$ g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
# 使用されているg++のパス確認。
$ type g++
g++ is /usr/bin/g++
gcc, g++のインストール状況を確認。
code:memo.sh
$ ls /usr/local/bin | grep gcc
gcc-8
gcc-ar-8
gcc-nm-8
gcc-ranlib-8
x86_64-apple-darwin18.2.0-gcc-8
x86_64-apple-darwin18.2.0-gcc-8.2.0
x86_64-apple-darwin18.2.0-gcc-ar-8
x86_64-apple-darwin18.2.0-gcc-nm-8
x86_64-apple-darwin18.2.0-gcc-ranlib-8
$ ls /usr/local/bin | grep g++
g++-8
x86_64-apple-darwin18.2.0-g++-8
gcc-8, g++-8が指定したいgccのエイリアスなのでシンボリックリンクを作成する。
code:memo
# シンボリックリンクの作成
$ ln -s /usr/local/bin/gcc-8 /usr/local/bin/gcc
$ ln -s /usr/local/bin/g++-8 /usr/local/bin/g++
gccが正しくリンクされているか確認。ここで正しくリンクされていない場合PATHの設定が悪い可能性がある。
code:memo
# gccが正しくリンクされているか確認。
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/8.2.0/libexec/gcc/x86_64-apple-darwin18.2.0/8.2.0/lto-wrapper
Target: x86_64-apple-darwin18.2.0
Configured with: ../configure --build=x86_64-apple-darwin18.2.0 --prefix=/usr/local/Cellar/gcc/8.2.0 --libdir=/usr/local/Cellar/gcc/8.2.0/lib/gcc/8 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 8.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk Thread model: posix
gcc version 8.2.0 (Homebrew GCC 8.2.0)
# g++を正しくリンクされているか確認
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/8.2.0/libexec/gcc/x86_64-apple-darwin18.2.0/8.2.0/lto-wrapper
Target: x86_64-apple-darwin18.2.0
Configured with: ../configure --build=x86_64-apple-darwin18.2.0 --prefix=/usr/local/Cellar/gcc/8.2.0 --libdir=/usr/local/Cellar/gcc/8.2.0/lib/gcc/8 --disable-nls --enable-checking=release --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-8 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-isl=/usr/local/opt/isl --with-system-zlib --with-pkgversion='Homebrew GCC 8.2.0' --with-bugurl=https://github.com/Homebrew/homebrew-core/issues --disable-multilib --with-native-system-header-dir=/usr/include --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk Thread model: posix
gcc version 8.2.0 (Homebrew GCC 8.2.0)
うまくいってない場合、PATHを設定した方がする。
code:.bashrc
export PATH=/usr/local/bin/:$PATH
以下を実行して実行できることを確認。
code:memo.sh
$ cmake .
$ make
$ ./DisplayImage
[0, 1, 2;
3, 4, 5;
6, 7, 8]
大変だった...。
悪戦苦闘 1
パスをincludeしてもうまく行かなかった。
code:memo
$ gcc -I /usr/local/Cellar/opencv/4.0.1/include/ -L /usr/local/Cellar/opencv/4.0.1/lib/ -ohellocv -lopencv_core -lstdc++ opencv_sample.cpp
In file included from opencv_sample.cpp:9:
/usr/local/Cellar/opencv/4.0.1/include/opencv4/opencv2/core/core.hpp:48:10: fatal error: 'opencv2/core.hpp' file not found
^~~~~~~~~~~~~~~~~~
1 error generated.
公式を調べるとCMakeLists.txtを使うようになっている。
code:CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage opencv_sample.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
悪戦苦闘 2
makeすると色々なエラーが起きた。
code:memo.txt
$ make
Scanning dependencies of target DisplayImage
50% Building CXX object CMakeFiles/DisplayImage.dir/opencv_sample.cpp.o In file included from /Users/pogin/Dropbox/100_repo/ghworkspace/language/c-c++/opencv/opencv_sample.cpp:10:
In file included from /usr/local/include/opencv4/opencv2/opencv.hpp:52:
In file included from /usr/local/include/opencv4/opencv2/core.hpp:52:
/usr/local/include/opencv4/opencv2/core/cvdef.h:656:4: error: "OpenCV 4.x+ requires enabled C++11 support"
# error "OpenCV 4.x+ requires enabled C++11 support"
^
In file included from /Users/pogin/Dropbox/100_repo/ghworkspace/language/c-c++/opencv/opencv_sample.cpp:10:
In file included from /usr/local/include/opencv4/opencv2/opencv.hpp:52:
In file included from /usr/local/include/opencv4/opencv2/core.hpp:57:
/usr/local/include/opencv4/opencv2/core/matx.hpp:143:15: error: no template named 'initializer_list' in namespace 'std'
Matx(std::initializer_list<_Tp>); //!< initialize from an initializer list
~~~~~^
/usr/local/include/opencv4/opencv2/core/matx.hpp:361:14: error: no template named 'initializer_list' in namespace 'std'
Vec(std::initializer_list<_Tp>);
~~~~~^
/usr/local/include/opencv4/opencv2/core/matx.hpp:664:28: error: no template named 'initializer_list' in namespace 'std'
Matx<_Tp, m, n>::Matx(std::initializer_list<_Tp> list)
~~~~~^
/usr/local/include/opencv4/opencv2/core/matx.hpp:1016:24: error: no template named 'initializer_list' in namespace 'std'
Vec<_Tp, cn>::Vec(std::initializer_list<_Tp> list)
~~~~~^
In file included from /Users/pogin/Dropbox/100_repo/ghworkspace/language/c-c++/opencv/opencv_sample.cpp:10:
In file included from /usr/local/include/opencv4/opencv2/opencv.hpp:52:
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58:
/usr/local/include/opencv4/opencv2/core/types.hpp:2371:29: error: no member named 'val' in 'cv::Scalar_<float>'
return Scalar_<float>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2371:43: error: no member named 'val' in 'cv::Scalar_<float>'
return Scalar_<float>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2371:57: error: no member named 'val' in 'cv::Scalar_<float>'
return Scalar_<float>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2371:71: error: no member named 'val' in 'cv::Scalar_<float>'
return Scalar_<float>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2378:30: error: no member named 'val' in 'cv::Scalar_<double>'
return Scalar_<double>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2378:44: error: no member named 'val' in 'cv::Scalar_<double>'
return Scalar_<double>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2378:58: error: no member named 'val' in 'cv::Scalar_<double>'
return Scalar_<double>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2378:72: error: no member named 'val' in 'cv::Scalar_<double>'
return Scalar_<double>(a.val0 * s, a.val1 * s, a.val2 * s, a.val3 * s); ~ ^
/usr/local/include/opencv4/opencv2/core/types.hpp:2411:24: error: no matching constructor for initialization of 'Matx<double, 4, 1>'
Matx<double, 4, 1> c((Matx<double, 4, 4>)a, b, Matx_MatMulOp());
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/matx.hpp:203:28: note: candidate constructor not viable: no known conversion from 'Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument
template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:122:5: note: candidate constructor not viable: no known conversion from 'Matx<double, 4, 4>' to 'double' for 1st argument
Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:201:5: note: candidate constructor not viable: no known conversion from 'Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:202:5: note: candidate constructor not viable: no known conversion from 'Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:204:5: note: candidate constructor not viable: no known conversion from 'Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:205:5: note: candidate constructor not viable: no known conversion from 'Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument
Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:206:21: note: candidate template ignored: could not match 'Matx' against 'Scalar_'
template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:121:5: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:207:5: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:123:5: note: candidate constructor not viable: requires 4 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:120:14: note: candidate constructor not viable: requires single argument 'v0', but 3 arguments were provided
explicit Matx(_Tp v0); //!< 1x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:141:14: note: candidate constructor not viable: requires single argument 'vals', but 3 arguments were provided
explicit Matx(const _Tp* vals); //!< initialize from a plain array
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:99:44: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
template<typename _Tp, int m, int n> class Matx
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:124:5: note: candidate constructor not viable: requires 5 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:118:5: note: candidate constructor not viable: requires 0 arguments, but 3 were provided
Matx();
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:125:5: note: candidate constructor not viable: requires 6 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:126:5: note: candidate constructor not viable: requires 7 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:127:5: note: candidate constructor not viable: requires 8 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:128:5: note: candidate constructor not viable: requires 9 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:129:5: note: candidate constructor not viable: requires 10 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:130:5: note: candidate constructor not viable: requires 12 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:133:5: note: candidate constructor not viable: requires 14 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:137:5: note: candidate constructor not viable: requires 16 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
In file included from /Users/pogin/Dropbox/100_repo/ghworkspace/language/c-c++/opencv/opencv_sample.cpp:10:
In file included from /usr/local/include/opencv4/opencv2/opencv.hpp:52:
In file included from /usr/local/include/opencv4/opencv2/core.hpp:58:
/usr/local/include/opencv4/opencv2/core/types.hpp:2418:24: error: no matching constructor for initialization of 'Matx<double, 4, 1>'
Matx<double, 4, 1> c(a, b, Matx_MatMulOp());
^ ~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/opencv4/opencv2/core/matx.hpp:203:28: note: candidate constructor not viable: no known conversion from 'const Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument template<typename _T2> Matx(const Matx<_Tp, m, n>& a, _T2 alpha, Matx_ScaleOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:122:5: note: candidate constructor not viable: no known conversion from 'const Matx<double, 4, 4>' to 'double' for 1st argument
Matx(_Tp v0, _Tp v1, _Tp v2); //!< 1x3 or 3x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:201:5: note: candidate constructor not viable: no known conversion from 'const Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_AddOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:202:5: note: candidate constructor not viable: no known conversion from 'const Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_SubOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:204:5: note: candidate constructor not viable: no known conversion from 'const Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_MulOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:205:5: note: candidate constructor not viable: no known conversion from 'const Matx<2 * ..., 4>' to 'const Matx<2 * ..., 1 aka 1>' for 1st argument Matx(const Matx<_Tp, m, n>& a, const Matx<_Tp, m, n>& b, Matx_DivOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:206:21: note: candidate template ignored: could not match 'Matx' against 'Scalar_'
template<int l> Matx(const Matx<_Tp, m, l>& a, const Matx<_Tp, l, n>& b, Matx_MatMulOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:121:5: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1); //!< 1x2 or 2x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:207:5: note: candidate constructor not viable: requires 2 arguments, but 3 were provided
Matx(const Matx<_Tp, n, m>& a, Matx_TOp);
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:123:5: note: candidate constructor not viable: requires 4 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3); //!< 1x4, 2x2 or 4x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:120:14: note: candidate constructor not viable: requires single argument 'v0', but 3 arguments were provided
explicit Matx(_Tp v0); //!< 1x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:141:14: note: candidate constructor not viable: requires single argument 'vals', but 3 arguments were provided
explicit Matx(const _Tp* vals); //!< initialize from a plain array
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:99:44: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 3 were provided
template<typename _Tp, int m, int n> class Matx
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:124:5: note: candidate constructor not viable: requires 5 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4); //!< 1x5 or 5x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:118:5: note: candidate constructor not viable: requires 0 arguments, but 3 were provided
Matx();
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:125:5: note: candidate constructor not viable: requires 6 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5); //!< 1x6, 2x3, 3x2 or 6x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:126:5: note: candidate constructor not viable: requires 7 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6); //!< 1x7 or 7x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:127:5: note: candidate constructor not viable: requires 8 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7); //!< 1x8, 2x4, 4x2 or 8x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:128:5: note: candidate constructor not viable: requires 9 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8); //!< 1x9, 3x3 or 9x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:129:5: note: candidate constructor not viable: requires 10 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3, _Tp v4, _Tp v5, _Tp v6, _Tp v7, _Tp v8, _Tp v9); //!< 1x10, 2x5 or 5x2 or 10x1 matrix
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:130:5: note: candidate constructor not viable: requires 12 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:133:5: note: candidate constructor not viable: requires 14 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
/usr/local/include/opencv4/opencv2/core/matx.hpp:137:5: note: candidate constructor not viable: requires 16 arguments, but 3 were provided
Matx(_Tp v0, _Tp v1, _Tp v2, _Tp v3,
^
In file included from /Users/pogin/Dropbox/100_repo/ghworkspace/language/c-c++/opencv/opencv_sample.cpp:10:
In file included from /usr/local/include/opencv4/opencv2/opencv.hpp:52:
In file included from /usr/local/include/opencv4/opencv2/core.hpp:59:
/usr/local/include/opencv4/opencv2/core/mat.hpp:1007:29: error: no template named 'initializer_list' in namespace 'std'
explicit Mat(const std::initializer_list<_Tp> list);
~~~~~^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1011:52: error: no template named 'initializer_list' in namespace 'std'
template<typename _Tp> explicit Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list);
~~~~~^
/usr/local/include/opencv4/opencv2/core/mat.hpp:1011:92: error: no template named 'initializer_list' in namespace 'std'
template<typename _Tp> explicit Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> list);
~~~~~^
/usr/local/include/opencv4/opencv2/core/mat.hpp:2222:15: error: no template named 'initializer_list' in namespace 'std'
Mat_(std::initializer_list<_Tp> values);
~~~~~^
20 errors generated.
最初の方の以下のエラーを調べてみる。
code:memo.txt
In file included from /usr/local/include/opencv4/opencv2/core.hpp:52:
/usr/local/include/opencv4/opencv2/core/cvdef.h:656:4: error: "OpenCV 4.x+ requires enabled C++11 support"
# error "OpenCV 4.x+ requires enabled C++11 support"
^
見てみると-std=c++11 を有効にしないといけないらしい。
なので-std=c++11 を有効にしないといけないらしい。なので有効にしてみる。
code:memo
$ g++ -dM -E -x c++ -std=c++11 (pkg-config --libs --cflags opencv4) -L/usr/local/include/ opencv_sample.cpp /dev/null | grep plus
opencv_sample.cpp:10:10: fatal error: 'opencv2/opencv.hpp' file not found
^~~~~~~~~~~~~~~~~~~~
1 error generated.
有効にしてもなぜか有効にならないし、それ以前になぜかNot Foundではある。とりあえず有効にするためにCMakeLists.txtで有効にするためのオプションを調べてみるとなんとか見つけれた。add_definitions(-std=c++11)を追加すれば良さそう。
code:CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
# ↓↓↓↓↓↓↓↓↓↓↓↓追加↓↓↓↓↓↓↓↓↓↓↓↓
add_definitions(-std=c++11)
# ↑↑↑↑↑↑↑↑↑↑↑↑追加↑↑↑↑↑↑↑↑↑↑↑↑
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( DisplayImage opencv_sample.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )