1

I'm trying to install OpenCV on Raspbian so that I can deploy my Java code onto the RPi. However, having cmake find JNI is proving to be an irksome task. One question that was answered here noted that the administrator needed to have JAVA_HOME set as well, not just the user. So I set it in /etc/environment as well as the prior setting in .bashrc.

How to resolve "Could not find JNI", building OpenCV on Raspberry Pi?

However, cmake still cannot find JNI, even after I updated it to find the Include directories as noted in the following;

cmake find_package(JNI) not work in Ubuntu 12.04 amd64

I've tried many different combinations, including the Java installation and environment setting at, though it unzips java in /opt/java and recommends setting JAVA_HOME to there;

http://elinux.org/RPi_Java_JDK_Installation

Pertinent FindJNI.cmake lines include;

SET(JAVA_AWT_INCLUDE_DIRECTORIES
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
  "[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
  ${_JAVA_HOME}/include
  /usr/include 
  /usr/local/include
  /usr/lib/java/include
  /usr/local/lib/java/include
  /usr/lib/jvm/jdk-7-oracle-armhf/include  <-- Added by me

and

JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
  ${_JAVA_HOME}/jre/lib/{libarch}
  ${_JAVA_HOME}/jre/lib
  ${_JAVA_HOME}/lib
  ${_JAVA_HOME}
  /usr/lib
  /usr/local/lib
  /usr/lib/jvm/java/lib
  /usr/lib/java/jre/lib/{libarch}
  /usr/lib/jvm/jdk-7-oracle-armhf
  /usr/lib/jvm/jdk-7-oracle-armhf/lib
  /usr/lib/jvm/jdk-7-oracle-armhf/lib/{libarch}
  /usr/lib/jvm/jdk-7-oracle-armhf/{libarch}

Pertinent OpenCV install script lines include;

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_SHARED_LIBS=OFF  -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON WITH_QT=ON -D WITH_OPENGL=ON ..
make -j 8
sudo make install

Cmake output includes;

-- Could NOT find JNI (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY)
System is unknown to cmake, create: Platform/error pid:6186, boost::interprocess::bad_alloc Linux to use this system, please send your config file to cmake@www.cmake.org so

I'm at a loss for any more clues to load OpenCV on Raspbian where Java can be used - what else do I need to do?

Community
  • 1
  • 1
Will
  • 79
  • 2
  • 11

3 Answers3

2

Try this.

open Terminal < export JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf

In my case I have installed java-7-openjdk-armhf and it worked for me when building opencv.

Chris
  • 5,882
  • 2
  • 32
  • 57
Rhymee_Uv
  • 21
  • 2
1

I ran into the same issue as you. The only thing that worked for me was specifying the missing paths as parameter to the cmake command.

I followed the instructions from the OpenCV website (OpenCV Java Tutorial) but modified the cmake command like this:

cmake -D BUILD_SHARED_LIBS=OFF -DJAVA_INCLUDE_PATH=/usr/lib/jvm/jdk-7-oracle-armhf/include -DJAVA_AWT_LIBRARY=/usr/lib/jvm/jdk-7-oracle-armhf/jre/lib/amd64/libawt.so -DJAVA_JVM_LIBRARY=/usr/lib/jvm/jdk-7-oracle-armhf/jre/lib/arm/server/libjvm.so ..

In your case, you're saying that you receives the message (missing: JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY), so you might only need to specify those...

Hope this helps! Good luck.

MathieuB
  • 88
  • 2
  • 7
0

Although this is an old question I have create a fork of OpenCV 3.1.0 here which builds an OSGi-compatible JAR (bundle) for OpenCV (as well as the standard artifacts) using Maven. One of the things it does is check the build environment and native dependencies prior to build. See the README guide on the page for further information.

D-Dᴙum
  • 7,689
  • 8
  • 58
  • 97