|Ubuntu 18.04,opencv-3.4.0,MATLAB/R2018a| make 在对 cv::dnn::eperimental 的未定义引用上失败

|Ubuntu 18.04, opencv-3.4.0, MATLAB/R2018a| make fails on undefined reference to cv::dnn::eperimental

我已经按照 wiki 的步骤安装 mexopencv,但我收到以下错误:

$ make MATLABDIR=/usr/local/MATLAB/R2018a WITH_CONTRIB=true all contrib    

/tmp/mex_17713079591682_20541/Net_.o: In function `mexFunction':
    Net_.cpp:(.text+0x10dd): undefined reference to `cv::dnn::experimental_dnn_v3::Net::Net()'
    Net_.cpp:(.text+0x11ac): undefined reference to `cv::dnn::experimental_dnn_v3::readNetFromCaffe(cv::String const&, cv::String const&)'
    Net_.cpp:(.text+0x122a): undefined reference to `cv::dnn::experimental_dnn_v3::Net::~Net()'
    .. and so on

如果我看到要在 opencv 中构建什么,模块 dnn 存在,这让我感到奇怪。

-- General configuration for OpenCV 3.4.0 =====================================

--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dpm face features2d flann freetype fuzzy hdf highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    js python2 python3 world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern java matlab ovis sfm ts viz

内置模块:

$ pkg-config --cflags --libs opencv
-I/usr/local/include/opencv ..etc.. -lopencv_dnn .. etc

当前 opencv 版本是:

$ pkg-config --modversion opencv
3.4.0

问题是;有没有办法 workaround/fix 这个,即 disabling/unlinking dnn?

或者我如何实际编译使此引用正常工作所需的 dnn 文件?

{edit 1} 文件实际编译于:

$ ls /usr/local/include/opencv2/
...
bioinspired      dnn             fuzzy         imgproc              optflow               saliency      superres              videoio          xphoto.hpp
bioinspired.hpp  dnn.hpp         fuzzy.hpp     imgproc.hpp   
...

{edit 2} 通过添加以下内容在 mexopencv Makefile 中取消链接 -lopencv_dnn:

CV_LDFLAGS := $(filter-out -lopencv_dnn,$(CV_LDFLAGS))

不是一个选项,因为对 cv::dnn::experimental_dnn_v3 的未定义引用仍然编译失败。所以我想我需要解决这个问题。

找到了我的问题的解决方案。原因是 Opencv 安装部分盲目地遵循 mexopencv。我必须在 cmake 步骤中使用以下内容:

# build and compile opencv-3.4.0:
$ cmake -G "Unix Makefiles" \
    -DBUILD_DOCS=OFF \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_PERF_TESTS=OFF \
    -DBUILD_TESTS=OFF \
    -DBUILD_JAVA=OFF \
    -DWITH_CUDA=OFF \
    -DWITH_CUBLAS:BOOL=OFF \
    -DWITH_CUFFT:BOOL=OFF \
    -DWITH_NVCUVID:BOOL=OFF \
    -DBUILD_opencv_cudaarithm:BOOL=OFF \
    -DBUILD_opencv_cudabgsegm:BOOL=OFF \
    -DBUILD_opencv_cudacodec:BOOL=OFF \
    -DBUILD_opencv_cudafeatures2d:BOOL=OFF \
    -DBUILD_opencv_cudafilters:BOOL=OFF \
    -DBUILD_opencv_cudaimgproc:BOOL=OFF \
    -DBUILD_opencv_cudalegacy:BOOL=OFF \
    -DBUILD_opencv_cudaobjdetect:BOOL=OFF \
    -DBUILD_opencv_cudaoptflow:BOOL=OFF \
    -DBUILD_opencv_cudastereo:BOOL=OFF \
    -DBUILD_opencv_cudawarping:BOOL=OFF \
    -DBUILD_opencv_cudev:BOOL=OFF \
    -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_js=OFF \
    -DBUILD_opencv_python2=OFF \
    -DBUILD_opencv_python3=OFF \
    -DBUILD_opencv_ts=OFF \
    -DBUILD_opencv_world=OFF \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr/local \
    -DOPENCV_ENABLE_NONFREE=ON \
    -DOPENCV_EXTRA_MODULES_PATH=~/cv/opencv_contrib-3.4.0/modules ~/cv/opencv-3.4.0
$ make -j8  # -j$(nproc)
$ sudo make install

# compile mexopencv = OK
$ make MATLABDIR=/usr/local/MATLAB/R2018a WITH_CONTRIB=true all contrib

与 wiki 的主要区别在于从 cmake 步骤中删除了以下两行:

-DWITH_MATLAB=OFF \
-DBUILD_opencv_matlab=OFF \