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 ant
sudo 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-dev
Step 2 – Set Environment Variables:
JAVA_HOMEVariable ! In our case we also need the
PATHset 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 -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 „
/etc/alternatives/java“ returns: „
ANT_HOMEand also add it to the
PATHvariable. For this i use the nano editor.
nano ~/.bashrc“ (CTRL + V till you reach the very bottom of the file)
Step 3 – Downloading OpenCV 3.1.0:
mv 3.1.0 opencv.zip
Step 4 – Compiling:
mkdir build“ and navigate into it „
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 „
-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. :-/
build/libs„. There should be a file called „
libopencv_java310.so“ and a „
opencv-310.jar“ in the folder „