Adventures in OpenCV Building: OpenCV + Contrib 3.4 build results in neutered Java and Python files and no Matlab bindings

asked 2018-02-15 02:36:56 -0600

sid311 gravatar image

Hello All,

So I have been trying to successfully build OpenCV + Contrib 3.4 for about a week. My setup is as follows:

  • CMake 3.10.2 using Visual Studio 15 2017 Win64 (as seen in one of the screenshots above)
  • OpenCV 3.4.0 and OpenCV_Contribute 3.4.0 (assumed, latest build from GitHub)
  • Matlab 2017b, C++ compiler set as Microsoft Visual C++ 2017, Computer Vision System Toolbox OpenCV Interface installed (v 17.2.1.0)
  • Python 3.6.4 64 bit w/ Numpy (ver 1.14.0)
  • Windows 10 Pro 64 bit 64 bit Windows 10 Pro 64 bit

I've set the following options, I can configure and generate without errors:

  • VTK 8.1.0
  • GStreamer 1.12.4 (Regular and Dev installed)
  • OpenNI2 (ver 2.2.0, build 33)
  • Intel TBB (ver 2018.0 interface 10001)
  • Intel IPP (ICV version): 2017.0.3 [2017.0.3] (I have the 2018.0 version, but don't know how to make CMake locate it.)
  • Intel MKL 2018.0
  • LAPACK(MKL)
  • Apache Ant (ver 1.10.2)

I've spent the week building from vanilla and each subsequent extra, one by one. I only have trouble with open_matlab not being built because of errors:

Output:

Failed to compile CamShift: CamShift.cpp
CUSTOMBUILD : error C2065: 'type': undeclared identifier
CUSTOMBUILD : error C2664: 'cv::Mat::Mat(cv::Mat &&)': cannot convert argument 1 from
4>  '::size_t' to 'cv::Size'

Errors:

Error   C2039   'type': is not a member of 'cv::DataType<Scalar>'
Error   C2065   'type': undeclared identifier   
Error   C2664   'cv::Mat::Mat(cv::Mat &&)': cannot convert argument 1 from

Everything else seems to build fine. I've built the ALL_BUILD project in both Debug and Release configurations and also the INSTALL soon after, also in both Debug and Release configurations.

On top of that, my Java files and Python files don't work:

My Java files: opencv-340.jar = 601kb, opencv_java340.dll = 2.2MB; while the ones from the official Windows pack are 403kb and 44.1MB, respectively.

My python file: cv2.cp36-win_amd64.pyd = 6.4MB, while the unofficial prebuilt Python libraries, opencv-python 3.4.0.12, comes in at 78.7MB.

Testing a small Java program in Eclipse, i get scolded with:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\OpenCV\build\install\java\x64\opencv_java340.dll: Can't find dependent libraries
    at java.base/java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.base/java.lang.ClassLoader.loadLibrary0(Unknown Source)
    at java.base/java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.base/java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.base/java.lang.System.loadLibrary(Unknown Source)
    at opencv_helloworld.HelloCV.main(HelloCV.java:10)

And testing the Python library by importing cv2 with the Python interpreter from the command prompt greets me with:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

or

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 ...
(more)
edit retag flag offensive close merge delete

Comments

could you add the cmake output to your question ?

(it seems , you have been building dynamic opencv libs, so you need to put the folder containing those on the PATH environment variable, so your c++/python/java program can find those at runtime)

if you want to avoid the dll dependancies, you have to build with cmake -DBUILD_SHARED_LIBS=OFF

berak gravatar imageberak ( 2018-02-15 02:46:36 -0600 )edit

Hmm I think I've tried that, I remember seeing that tip in one of the Java tutorials, but maybe I wasn't paying attention.

In any case, I will try again tomorrow as I've trashed everything tonight. But I've built it so many times I can do it by memory now.

I'll post the output tomorrow, thanks.

sid311 gravatar imagesid311 ( 2018-02-15 03:25:40 -0600 )edit

Here is my CMake Output and my CMake Variables just incase.

sid311 gravatar imagesid311 ( 2018-02-16 01:28:01 -0600 )edit

In order to for CMake-GUI to find the 2018 version of IPP, follow these instructions.

In a nutshell, create a new entry IPPROOT and set it to the IPP folder in your Intel IDE install folder. For example, mine was C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2018.1.156/windows/ipp.

sid311 gravatar imagesid311 ( 2018-02-16 10:35:39 -0600 )edit

So by unchecking BUILD_SHARED_LIBS it results in huge 180MB python file, but I still receive the same error as above. Didn't bother testing the Java or the rest.

I'm going to work backwards and start full builds removing extras one by one. It has to be an extra that is not building correctly and interfering with everything else.

sid311 gravatar imagesid311 ( 2018-02-17 10:12:09 -0600 )edit

Ok, so I had to disable the building of shared libs and opencv_world. First, it gave me a usable python file (import cv2 works) but it only gave me a Java JAR file. I enabled shared libs to create a Java DLL but it was small and useless. However, I disabled shared libs and rebuilt it, leaving the Java DLL. VS seems to have built into the DLL file even though i had shared libs off.

I wonder why didn't the Java DLL get built the first time, if both the JAR and DLL are needed and why it got written to when shared libs are off.

I still need opencv_world, will build later.

Note: Had to disable VTK, GStreamer, OpenNI2 and Matlab. One of those causes an issue. :(

sid311 gravatar imagesid311 ( 2018-02-18 00:42:44 -0600 )edit

Ok I built opencv_world without errors and VS complained about a missing zlib DLL when I tried to compile the sample C++ program I mentioned earlier; had to find it in the 3rd Party folder and copy the LIBs and DLLs manually to the appropriate folder.

Now to build everything all over again and see what extra is causing problems. >:(

sid311 gravatar imagesid311 ( 2018-02-18 03:12:49 -0600 )edit