Part 1: Installing OpenCV 3.1.0 on Raspberry Pi Debian Jessy with Java Library
The Raspberry Pi has become a Icon. I have nearly 10 Raspberry Pis and i love every single one of them. ;-) In December 2015 I started my Smart Mirror (Magic Mirror) Project and now its finally ready. Or better said the Hardware or the Smart Mirror is finally ready. What is now missing is a mind blowing Software. While searching for features a friend of my, Hendrik, came up with a mind blowing idea. A absolute key feature for a Smart Mirror - Face recognition. (At this points dear Magic-Mirrors-Startups: In case you want to copy this idea now, act fairly enough and publish were you got this idea from).
However, since it is not so easy, here it comes: How to install OpenCV 3.1.0 on a Raspberry Pi with Java Support.
If you have a fresh Debian Jessy Image on the PI (I use the March 2016 image) it should work perfectly when you follow the steps.
Step 1 - Required Packages:
So the first thing you want to do is installing all the necessary packages.
sudo apt-get update && sudo apt-get install oracle-java7-jdk cmake antsudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs libavcodec-dev libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-devStep 2 - Set Environment Variables:
JAVA_HOME Variable ! In our case we also need the ANT_HOME.PATH set and we don't know which path we need to take.which" tells you the total path of a application. If we enter "which ant" we get "/usr/bin/ant". BUT this is not where ant is actually located. To find out we need "ls". "ls -l /usr/bin/ant" tells us more: "/usr/bin/ant -> ../share/ant/bin/ant". Jackpot - That the path we where locking for. The same for Java. "which java" leads us to "/usr/bin/java". And "ls -l /usr/bin/java" is pointing to "/etc/alternatives/java". Which is not what we are looking for because it is another link. So "ls -l /etc/alternatives/java" returns: "/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/jre/bin/java". BINGO..bashrc file, set JAVA_HOME and ANT_HOME and also add it to the PATH variable. For this i use the nano editor.nano ~/.bashrc" (CTRL + V till you reach the very bottom of the file)export ANT_HOME=/usr/share/ant/export PATH=${PATH}:${ANT_HOME}/binexport JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/export PATH=$PATH:$JAVA_HOME/binsudo reboot" Step 3 - Downloading OpenCV 3.1.0:
wget https://codeload.github.com/Itseez/opencv/zip/3.1.0mv 3.1.0 opencv.zipunzip opencv.zip cd opencv-3.1.0/Step 4 - Compiling:
mkdir build" and navigate into it "cd build"cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_OPENCL=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D JAVA_INCLUDE_PATH=$JAVA_HOME/include -D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libawt.so -D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so -D CMAKE_INSTALL_PREFIX=/usr/local ..-D BUILD_SHARED_LIBS=OFF " and "-D BUILD_PERF_TESTS=OFF".-j # flag. - However I had problems with this when compiling opencv and I would recommend to not use it. Even it will take like 2-3 h. :-/make"make install".build/libs". There should be a file called "libopencv_java310.so" and a "opencv-310.jar" in the folder "build/bin".