Author

Cristina Heredia

Outlier y graduada en Ing. Informática en la ugr. Computer science.

Cristina Heredia's posts | Porfolio

Table Of Contents

In my last post Compile OpenCV from source with JAVA support I explained how to Compile OpenCV from source with JAVA support, however, the OpenCV nonfree part was not included. If you are planning to use private features from OpenCV like SIFT or SURF descriptors, you should go as follows:

[1]. Download OpenCV 3.2, unpack and create build directory

following the steps of my last post.

[2]. Download and unpack nonfree part

nonfree part has been separated in OpenCV3+, so you need to download it separately from github opencv repo or clone the repository. Then extract opencv_contrib and move it inside your opencv folder :


cris@cris ~ $ cp Downloads/opencv-contrib opencv-3.2.0/

[3]. generate makefiles

we move to the build folder inside opencv folder and type:


cris@cris~$ cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release\\
-DCMAKE_INSTALL_PREFIX=../dist -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..

With DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules we are specifying where to found the nonfree part.

If makefiles generation went ok, you can now build. If using openCV in JAVA, you must make sure $JAVA_HOME variable is set to JDK’s path and visible to child processes. For that when doing: echo $JAVA_HOME the JDK path must be displayed. If not, in terminal, set de variable value to JDK path and export it, for example:


cris@cris ~$ export JAVA_HOME=/home/jdk1.8.0_111/

Notice that when generating the makefile, the output in the Java field looks like this:

That is, there is a specified ant and JNI path, and Java wrappers is set to YES.

[4]. Build

run make to build openCV with Java and create a jar:

cris@cris ~/opencv-3.2.0/build $ make -j8

Make sure the files opencv-320.jar and libopencv_java320.so (.so or .dll) are created inside /build.

cris@cris ~/opencv-3.2.0/build $ ls -R | grep opencv-320.jar
opencv-320.jar
opencv-320.jar.dephelper

cris@cris ~/opencv-3.2.0/build $ ls -R | grep libopencv_java320.so
libopencv_java320.so

[5]. Edit features2d_manual.hpp file

Ok, if building was successfull, then move to /modules/features2d/misc/java/src/cpp:

cris@cris ~/opencv-3.2.02 $ cd modules/features2d/misc/java/src/cpp/

and edit features2d_manual.hpp with your favorite text editor, as following:

//name = name + "SIFT"; by fd=xfeatures2d::SIFT::create(); and //name = name + "SURF"; by fd=xfeatures2d::SURF::create();

case SIFT:
    de = xfeatures2d::SIFT::create();
    break;
    case SURF:
    de = xfeatures2d::SURF::create();
    break;

[5].Rebuild to apply changes

move to your opencv/build folder and run make install when finished, you just need to include the .so and .jar files on your openCV project and you would be able to use SIFT and SURF decriptors in your code.

References:

Spot a typo?: Help me fix it by contacting me or commenting below!

Categories:Tags:

Maybe this posts are also worth reading