kyamagu/mexopencv

Error calling cv.imread() -- MxArray not of type char

BadWindshield opened this issue · 15 comments

  1. I am running Ubuntu 18.04, and compiled & installed my own OpenCV 3.4.1 . Instead of preloading libraries, I set up symbolic links for these three MATLAB .so's:
lrwxrwxrwx 1 root root      35 Nov  3 16:45 libgcc_s.so.1 -> /lib/x86_64-linux-gnu/libgcc_s.so.1
lrwxrwxrwx 1 root root      45 Nov  3 16:22 libstdc++.so.6 -> /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25
lrwxrwxrwx 1 root root      37 Nov  3 16:53 libtbb.so.2 -> /usr/lib/x86_64-linux-gnu/libtbb.so.2
  1. I was able to run unit tests inside MATLAB
>> UnitTest('ContribModules',true)
...
1411 Passed, 7 Failed, 54 Incomplete
  1. However, when I try to load an image using cv.imread(), I get
>> im = cv.imread("test/stuff.jpg")
Error using imread
MxArray not of type char
  1. This might be another symptom. When I run make test, it will hang at the TestFilterSpeckles test.

OMG I figured it out. After programming in C++ and Python for a while, I forgot that strings in MATLAB use single quotes.

Right, MATLAB R2016b introduced string arrays as a new data type for text, created with double-quotes. The original single-quotes create character arrays, which are like regular numeric arrays storing characters instead of numbers.

https://www.mathworks.com/help/matlab/characters-and-strings.html

If you come from C++ background, think of it like char* as a basic array of bytes vs. std::string as a container class for text.

Also I'm curious, what are the "7 failed" tests above?

@amroamroamro I cannot reproduce the problem as the unit tests are no longer running through inside MATLAB =) It is hung somewhere.

When I ran make test, it is hung at TestFilterSpeckles.test_1. However, when I execute each line of TestFilterSpeckles.test_1 manually inside MATLAB, it runs through. Hmm

By printing statements to stdout, I isolated the line that hangs during make test:

DD = cv.filterSpeckles(D, 0, 50, 16);

Any ideas? The same line of code ran ok inside MATLAB (using the regular GUI).

Inside the MATLAB GUI, I can also cd to test/unit_tests and ran

>> tf = TestFilterSpeckles()
tf =
  TestFilterSpeckles with no properties.
>> tf.test_1()

I can open a new ticket to track this.

Uninstalling g++ v 7.3.0 and installing g++ v 4.8.5 didn't help. The unit tests failed earlier at number somewhere in the 100s. This is so frustrating.

Hmm, I don't see anything obvious why it would get stuck on that particular test..

Just to be sure, please run the following in MATLAB and post the output here:

>> version
>> cv.getBuildInformation()
>> ls(fullfile(matlabroot,'bin','glnxa64','libopencv*'))
>> !ldd /path/to/mexopencv/+cv/filterSpeckles.mexa64

When you run the unit tests, specify UnitTest('ContribModules',true, 'Verbosity',2) and post the full output for the tests that fail. Also if for some reason MATLAB itself crashes, please also include any crash dumps.

>> cv.getBuildInformation()

General configuration for OpenCV 3.4.1 =====================================
  Version control:               3.4.1

  Extra modules:
    Location (extra):            /home/williamw/Will/opencv_contrib/modules
    Version control (extra):     3.4.1

  Platform:
    Timestamp:                   2018-11-04T23:15:18Z
    Host:                        Linux 4.15.0-38-generic x86_64
    CMake:                       3.10.2
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               RELEASE

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (3 files):          + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (1 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++11:                       YES
    C++ Compiler:                /usr/bin/c++  (ver 7.3.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

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

  GUI: 
    GTK+:                        YES (ver 2.24.32)
      GThread :                  YES (ver 2.56.2)
      GtkGlExt:                  NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
    WEBP:                        build (ver encoder: 0x020e)
    PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)
    TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.0.9)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)

  Video I/O:
    DC1394:                      YES (ver 2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (ver 57.107.100)
      avformat:                  YES (ver 57.83.100)
      avutil:                    YES (ver 55.78.100)
      swscale:                   YES (ver 4.8.100)
      avresample:                NO
    GStreamer:                   NO
    libv4l/libv4l2:              NO
    v4l/v4l2:                    linux/videodev2.h
    gPhoto2:                     YES

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2017.0.3 [2017.0.3]
           at:                   /home/williamw/Will/opencv/build/3rdparty/ippicv/ippicv_lnx
    Intel IPP IW:                sources (2017.0.3)
              at:                /home/williamw/Will/opencv/build/3rdparty/ippicv/ippiw_lnx
    Lapack:                      YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
    Eigen:                       YES (ver 3.3.4)
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  NVIDIA CUDA:                   NO

  OpenCL:                        YES (no extra features)
    Include path:                /home/williamw/Will/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.15)
    Libraries:                   /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.15rc1)
    numpy:                       /usr/local/lib/python2.7/dist-packages/numpy/core/include (ver 1.15.3)
    packages path:               lib/python2.7/dist-packages

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.6.6)
    Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.6m.so (ver 3.6.6)
    numpy:                       /usr/local/lib/python3.6/dist-packages/numpy/core/include (ver 1.15.3)
    packages path:               lib/python3.6/dist-packages

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        YES
    mex:                         /usr/local/MATLAB/R2017a/bin/mex
    Compiler/generator:          Not working (bindings will not be generated)

  Install to:                    /usr/local
-----------------------------------------------------------------
>> !ldd +cv/filterSpeckles.mexa64
	linux-vdso.so.1 (0x00007ffec629a000)
	libgtk3-nocsd.so.0 => /usr/lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (0x00007f297abe8000)
	libopencv_calib3d.so.3.4 => /usr/local/lib/libopencv_calib3d.so.3.4 (0x00007f297a862000)
	libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007f297a206000)
	libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007f2977958000)
	libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007f2976a36000)
	libmx.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmx.so (0x00007f29766a4000)
	libmex.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmex.so (0x00007f2976469000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f29760e0000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f2975ec8000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2975ad7000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f29758d3000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f29756b4000)
	libopencv_features2d.so.3.4 => /usr/local/lib/libopencv_features2d.so.3.4 (0x00007f29753e1000)
	libopencv_flann.so.3.4 => /usr/local/lib/libopencv_flann.so.3.4 (0x00007f2975189000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f2974deb000)
	libjpeg.so.8 => /usr/lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f2974b83000)
	libpng16.so.16 => /usr/lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f2974951000)
	libtiff.so.5 => /usr/lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f29746da000)
	libIlmImf-2_2.so.22 => /usr/lib/x86_64-linux-gnu/libIlmImf-2_2.so.22 (0x00007f2974217000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f297400f000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f2973df2000)
	liblapack.so.3 => /usr/lib/x86_64-linux-gnu/liblapack.so.3 (0x00007f2973533000)
	libcblas.so.3 => /usr/lib/x86_64-linux-gnu/libcblas.so.3 (0x00007f2973311000)
	libmwresource_core.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwresource_core.so (0x00007f297310f000)
	libmwi18n.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwi18n.so (0x00007f2972dbe000)
	libut.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libut.so (0x00007f2972ada000)
	libmwfl.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwfl.so (0x00007f2972727000)
	libmwfoundation_usm.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwfoundation_usm.so (0x00007f2972506000)
	libboost_chrono.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_chrono.so.1.56.0 (0x00007f2972300000)
	libboost_date_time.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_date_time.so.1.56.0 (0x00007f29720ef000)
	libboost_filesystem.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_filesystem.so.1.56.0 (0x00007f2971ed9000)
	libboost_log.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_log.so.1.56.0 (0x00007f2971bfc000)
	libboost_regex.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_regex.so.1.56.0 (0x00007f29718ec000)
	libboost_signals.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_signals.so.1.56.0 (0x00007f29716d6000)
	libboost_system.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_system.so.1.56.0 (0x00007f29714d3000)
	libboost_thread.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_thread.so.1.56.0 (0x00007f29712b2000)
	libmwcpp11compat.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwcpp11compat.so (0x00007f2971094000)
	libicudata.so.56 => /usr/local/MATLAB/R2017a/bin/glnxa64/libicudata.so.56 (0x00007f296f6ae000)
	libicuuc.so.56 => /usr/local/MATLAB/R2017a/bin/glnxa64/libicuuc.so.56 (0x00007f296f311000)
	libicui18n.so.56 => /usr/local/MATLAB/R2017a/bin/glnxa64/libicui18n.so.56 (0x00007f296ee8a000)
	libicuio.so.56 => /usr/local/MATLAB/R2017a/bin/glnxa64/libicuio.so.56 (0x00007f296ec7d000)
	libtbb.so.2 => /usr/lib/x86_64-linux-gnu/libtbb.so.2 (0x00007f296ea41000)
	libtbbmalloc.so.2 => /usr/lib/x86_64-linux-gnu/libtbbmalloc.so.2 (0x00007f296e803000)
	libmwservices.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwservices.so (0x00007f296e1fe000)
	libmwmpath.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwmpath.so (0x00007f296df71000)
	libmwm_dispatcher.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwm_dispatcher.so (0x00007f296dc72000)
	libmwmlutil.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwmlutil.so (0x00007f296d41d000)
	libmwgenerate_diag_message.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwgenerate_diag_message.so (0x00007f296d215000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f297b013000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f296cfef000)
	libjbig.so.0 => /usr/lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f296cde1000)
	libHalf.so.12 => /usr/lib/x86_64-linux-gnu/libHalf.so.12 (0x00007f296cb9e000)
	libIex-2_2.so.12 => /usr/lib/x86_64-linux-gnu/libIex-2_2.so.12 (0x00007f296c980000)
	libIlmThread-2_2.so.12 => /usr/lib/x86_64-linux-gnu/libIlmThread-2_2.so.12 (0x00007f296c779000)
	libblas.so.3 => /usr/lib/x86_64-linux-gnu/libblas.so.3 (0x00007f296c1b7000)
	libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007f296bdd8000)
	libatlas.so.3 => /usr/lib/x86_64-linux-gnu/libatlas.so.3 (0x00007f296b84f000)
	libexpat.so.1 => /usr/local/MATLAB/R2017a/bin/glnxa64/libexpat.so.1 (0x00007f296b627000)
	libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f296b3ef000)
	libpam.so.0 => /lib/x86_64-linux-gnu/libpam.so.0 (0x00007f296b1e1000)
	libboost_serialization.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_serialization.so.1.56.0 (0x00007f296af81000)
	libunwind.so.8 => /usr/local/MATLAB/R2017a/bin/glnxa64/libunwind.so.8 (0x00007f296ad62000)
	libssl.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libssl.so.1.0.0 (0x00007f296aafa000)
	libcrypto.so.1.0.0 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f296a6b7000)
	libmwdisplay_device.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwdisplay_device.so (0x00007f296a4b0000)
	libmwlivecode.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwlivecode.so (0x00007f296a26f000)
	libmwcppmicroservices.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwcppmicroservices.so (0x00007f296a054000)
	libmwregexp.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwregexp.so (0x00007f2969e0b000)
	libmwsearch_path_interfaces.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwsearch_path_interfaces.so (0x00007f2969c06000)
	libmwstoragefilefolderobserver.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwstoragefilefolderobserver.so (0x00007f296998d000)
	libmwflstoragevfs.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflstoragevfs.so (0x00007f29696c4000)
	libmwcwf_interface.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwcwf_interface.so (0x00007f2969467000)
	libmwsettingscore.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwsettingscore.so (0x00007f2969025000)
	libmwms.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwms.so (0x00007f29689e3000)
	libmwnativedisplay.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwnativedisplay.so (0x00007f29687d8000)
	libmwopccore.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwopccore.so (0x00007f2968581000)
	libmwopcmodel.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwopcmodel.so (0x00007f29682ad000)
	libmwopczippackage.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwopczippackage.so (0x00007f296808a000)
	libmwopcmwservices.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwopcmwservices.so (0x00007f2967e28000)
	libmwwebproxy.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwwebproxy.so (0x00007f2967c1c000)
	libmwkeybrd.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwkeybrd.so (0x00007f2967a18000)
	libboost_iostreams.so.1.56.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libboost_iostreams.so.1.56.0 (0x00007f2967804000)
	libCppMicroServices.so.3.0.0 => /usr/local/MATLAB/R2017a/bin/glnxa64/libCppMicroServices.so.3.0.0 (0x00007f296753f000)
	libPocoCrypto.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoCrypto.so.31 (0x00007f296731d000)
	libPocoFoundation.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoFoundation.so.31 (0x00007f2966f34000)
	libPocoJSON.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoJSON.so.31 (0x00007f2966ce2000)
	libPocoNet.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoNet.so.31 (0x00007f29669ba000)
	libPocoNetSSL.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoNetSSL.so.31 (0x00007f2966771000)
	libPocoUtil.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoUtil.so.31 (0x00007f29664fe000)
	libPocoXML.so.31 => /usr/local/MATLAB/R2017a/bin/glnxa64/libPocoXML.so.31 (0x00007f296626d000)
	libxerces-c-3.1.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libxerces-c-3.1.so (0x00007f2965bbd000)
	libmwflnetwork.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflnetwork.so (0x00007f2965913000)
	libmwflstorageprovider.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflstorageprovider.so (0x00007f29656d5000)
	libmwstoragefileprovider.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwstoragefileprovider.so (0x00007f2965477000)
	libmwstorageshlibstoragesys.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwstorageshlibstoragesys.so (0x00007f2965235000)
	libmwflstorageevents.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflstorageevents.so (0x00007f2965018000)
	libmwcwf_implementation.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwcwf_implementation.so (0x00007f2964e10000)
	libmwmatlabstoragesystem.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwmatlabstoragesystem.so (0x00007f2964c0d000)
	libmwsearch_path_events.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwsearch_path_events.so (0x00007f2964a02000)
	libmwsearch_path_impl.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwsearch_path_impl.so (0x00007f296473a000)
	libmwsearch_path_utilities.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwsearch_path_utilities.so (0x00007f2964522000)
	libmwddux.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwddux.so (0x00007f2964306000)
	libmwxmlcore.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwxmlcore.so (0x00007f2964091000)
	libmwfoundation_extdata_array.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwfoundation_extdata_array.so (0x00007f2963e6d000)
	libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f2963c2d000)
	libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007f2963a04000)
	libmwflcrypto.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflcrypto.so (0x00007f29637d7000)
	libmwflcryptoutils.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflcryptoutils.so (0x00007f29635cb000)
	libmwflcryptocryptopp.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflcryptocryptopp.so (0x00007f296307b000)
	libminizip.so => /usr/lib/x86_64-linux-gnu/libminizip.so (0x00007f2962e70000)
	libmwstoragesharedlib.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwstoragesharedlib.so (0x00007f2962c54000)
	libmwmvm.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwmvm.so (0x00007f296270b000)
	libcap-ng.so.0 => /lib/x86_64-linux-gnu/libcap-ng.so.0 (0x00007f2962506000)
	libmwflcryptoopenssl.so => /usr/local/MATLAB/R2017a/bin/glnxa64/libmwflcryptoopenssl.so (0x00007f29622dc000)
>> ls(fullfile(matlabroot,'bin','glnxa64','libopencv*'))
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_calib3d.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_calib3d.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_core.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_core.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaarithm.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaarithm.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudabgsegm.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudabgsegm.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudacodec.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudacodec.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudafeatures2d.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudafeatures2d.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudafilters.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudafilters.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaimgproc.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaimgproc.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudalegacy.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudalegacy.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaobjdetect.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaobjdetect.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaoptflow.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudaoptflow.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudastereo.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudastereo.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudawarping.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudawarping.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudev.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_cudev.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_features2d.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_features2d.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_flann.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_flann.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_highgui.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_highgui.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_imgcodecs.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_imgcodecs.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_imgproc.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_imgproc.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_ml.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_ml.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_objdetect.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_objdetect.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_photo.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_photo.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_shape.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_shape.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_stitching.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_stitching.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_superres.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_superres.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_videoio.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_videoio.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_video.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_video.so.3.1.0
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_videostab.so.3.1
/usr/local/MATLAB/R2017a/bin/glnxa64/libopencv_videostab.so.3.1.0

All good there. So that rules out any library conflicts I was suspecting..

Now can you run the unit tests and include the full output of any errors:

>> UnitTest('ContribModules',true, 'Verbosity',2)

@amroamroamro Thanks for your help.

When the test fails, it hangs. I have to hit Ctrl-C to break the execution. There was no meaning output other than

[ 512 /1472] TestFilterSpeckles.test_1

ok, if you're up to a bit of debugging:

>> dbstop in TestFilterSpeckles at 10
>> TestFilterSpeckles.test_1
>> whos
>> imshow(single(D)/16,[])
>> dbstep

If not, I'll look into it more, but for now you can comment-out that line (and the line after it), and see if the rest of the unit-tests would run to completion.

I think the root cause was the well-known .so library incompatibility.

On a separate machine running Ubuntu 18.04, I use the built-in OpenCV 3.2.0 and sync the mexopencv to the v3.2.0 label. I had trouble running past test 153 (TestCalcBlurriness) until I renamed the libfreetype.so.6 in MATLAB.

I can now run through ALL of the unit tests:

$ make test
...
[1140/1141] TestWatershed.test_1                                         OK
[1141/1141] TestWatershed.test_error_argnum                              OK


Totals:
  1119 Passed, 0 Failed, 22 Incomplete
  Elapsed time is 49.144527 seconds.

This is the entire list of MATLAB .so's that I have to rename:

libstdc++
libgcc_s
libtbb
libtbbmalloc
libtiff
libxml2
libquadmath
libfreetype

Oh right, the ldd check on the mex-file might not show indirect conflicts in the dependencies. Try running it on the opencv libs as well:

>> !ldd /usr/local/lib/libopencv_calib3d.so.3.4

and compare it to when you run it outside MATLAB in a terminal:

$ ldd /usr/local/lib/libopencv_calib3d.so.3.4

Look for differences and preload them (or rename and replace with symlinks as you did).


Be sure to check libopencv_imgcodecs and libopencv_videoio which are likely to have the most external dependencies (image formats and such).