Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (90 sloc) 4.78 KB

Using JavaCV on CentOS 6.4

JavaCV is a "Java interface to OpenCV and more". OpenCV is the de facto standard of computer vision software enabling facial recognition, motion detection, general object detection to run over images. JavaCV incorporates with other technologies like ffmpeg allowing the same computer vision algorithms to intake videos.

If Java is language of choice, or the JVM, Java Bindings are used to interact with c/c++ libraries like OpenCV and ffmpeg. JavaCV provides all the jars pre-built including a jar that contains .so files, shared object files, for the various platforms, Mac, Linux and Windows. The intention is to not require a system level install of the OpenCV libraries.

CentOS 6.4 was unable to find the shared object files. JavaCV loaded the .so files from the provided jar and dynamically made the jnilib*.so files. Unfortunately the libc version provided with CentOS 6.4 is below the version the provided .so files were built for and the linking operation failed. To see what version of libc is installed, ldd --version. In this case 2.12 and the stack traces looked like this:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_objdetect in java.library.path
        at java.lang.ClassLoader.loadLibrary(
        at java.lang.Runtime.loadLibrary0(
        at java.lang.System.loadLibrary(
        at com.googlecode.javacpp.Loader.loadLibrary(
        at com.googlecode.javacpp.Loader.load(
        at com.googlecode.javacpp.Loader.load(
        at com.googlecode.javacv.cpp.opencv_objdetect.<clinit>(
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(
        at com.googlecode.javacpp.Loader.load(
        at Smoother.main(
Caused by: java.lang.UnsatisfiedLinkError: /tmp/javacpp8883169523366/ /lib64/ version `GLIBC_2.14' not found (required by /tmp/javacpp8883169523366/
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(
        at java.lang.ClassLoader.loadLibrary(
        at java.lang.Runtime.load0(
        at java.lang.System.load(
        at com.googlecode.javacpp.Loader.loadLibrary(

Try out the provided demo on CentOS 6.4

git clone && cd javacv-on-centos-6/demo
javac -cp javacv-linux-x86_64.jar:javacpp.jar:javacv.jar
java -cp javacv-linux-x86_64.jar:javacpp.jar:javacv.jar Smoother

This produces a similar stack trace from above.

To fix these errors, compile javacv-linux-x86_64.jar and OpenCV libraries on CentOS 6.4.

###Building OpenCV

Ensure JAVA_HOME defined. Something like /usr/lib/jvm/java

  1. Install system packages

     	sudo yum groupinstall "Development Tools"
     	sudo yum install cmake
     	sudo yum install ant
  2. Clone the OpenCV repository

     	 git clone && cd opencv
  3. Checkout desired release

     	 git checkout
  4. Make release directory

     	 mkdir release && cd release
  5. Generate make file, make and install

    This takes some time depending on the machine and what 3rd party libraries are built.

     	 sudo make install
  6. Ensure library files exist

     	 ls /usr/lib/*opencv*

###Building JavaCV

  1. Install maven if needed.

  2. Clone the JavaCV repository

     	git clone && cd javacv
  3. Checkout the latest release tag, 0.6 at this time.

     	git checkout 0.6
  4. Build the project

     	mvn install

    In step 3 c++ compiler commands execute and pick up on the libraries built in the "Building OpenCV" step.

  5. Copy the built jar

     	cp target/javacv-linux-x86_64.jar PATH_TO_DEMO_REPOSITORY/

###Using the jar built from source

Run the same test commands from above

javac -cp javacv-linux-x86_64.jar:javacpp.jar:javacv.jar
java -cp javacv-linux-x86_64.jar:javacpp.jar:javacv.jar Smoother

The correctly linked libjni file path prints.


The provided file attempts to load the shared library and print the path. To get started with JavaCV take a look at their cookbook.