在Linux中为OpenCV构建Java包

时间:2016-04-01 01:00:40

标签: java opencv

当我执行cmake命令时,"要构建"部分没有出现java,可能是什么原因?我在我的机器上安装了java

cmake -D CMAKE_BUILD_TYPE=Release -D BUILD_SHARED_LIBS=OFF -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-master/modules/ ..

To be built:
core flann imgproc ml photo reg surface_matching video dnn fuzzy
imgcodecs shape videoio highgui objdetect plot superres ts xobjdetect
xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency
text calib3d ccalib datasets rgbd stereo structured_light tracking
videostab xfeatures2d ximgproc aruco optflow stitching python2

Java版

java version "1.8.0_74"
Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)

环境变量也是正确设置的:

echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle/jre/bin/java

参考:http://docs.opencv.org/3.1.0/d7/d9f/tutorial_linux_install.html#gsc.tab=0

1 个答案:

答案 0 :(得分:0)

解决方案:在/usr/lib/jvm/jdk1.8.0_77//etc/environment中将JDK提取到~/.profile设置环境变量。

JAVA_HOME="/usr/lib/jvm/jdk1.8.0_77/"
JRE_HOME="/usr/lib/jvm/jdk1.8.0_77/jre/"

将java和javac添加到/ usr / bin

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_77/bin/java" 1000
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_77/bin/javac" 1000

确保它们当前已被选中:

sudo update-alternatives --config java
sudo update-alternatives --config javac

/usr/share/cmake-3.2/Modules/FindJNI.cmake包含

部分的文件JAVA_AWT_LIBRARY_DIRECTORIES
/usr/lib/jvm/jdk1.8.0_77/jre/lib/{libarch}

JAVA_AWT_INCLUDE_DIRECTORIES包含

部分
/usr/lib/jvm/jdk1.8.0_77/include

安装' ant'并检查/usr/bin/ant -version是否说JAVA_HOME错误的路径或其他东西。 最后cmake现在应该能够为java编译库了。

谢谢Dan。

附录

要在java中编译OpenCv的额外模块,请转到首选模块目录中包含的CMakeList.txt并添加' java'到线:

ocv_define_module(face opencv_core opencv_imgproc opencv_objdetect WRAP python java)

取消设置BUILD_SHARED_LIBS,BUILD_EXAMPLES,BUILD_TESTS,BUILD_PERF_TESTS,标记并将OPENCV_EXTRA_MODULES_PATH设置为路径:opencv_contrib/modules/