Installing OpenCv 3.0 and Javacv on Raspberry Pi

Preface
---------

I had a free raspberry pi's version B lying around and a spare PS3 eye and a few hours in hand { which later extended to days and week :) }. Decided to use Javacv for a quick IP-Cam setup and a simple face recognition(Dint get time to work till now). 

Thanks a lot for Samuel Audet for helping out with a lot of issues.

https://groups.google.com/forum/#!topic/javacv/Ql1v5THKIcQ

Going through the above link you can read all my interactions with Samuel.

This is gonna be a pretty lengthy post. Read through if you need to compile a later version if not simply skip to interesting parts and links.

Events
---------

Step 1

Look for existing tutorial and I did found one,very well explained with steps 


Went through the steps, installed the opencv version 2.4. Opencv installation success (!yaay!) .

Developer in me decided I will take a latest version of javacv and javacpp and compile it so that I can use latest features in javacv { Being a full time java developer maven build should be a breeze !! }.

went on to compile Javacpp 1.0 !! believe it or not success again..

Last and final step compile javacv 1.0. Good guess - it failed with the weirdest error for a person from java background
/home/pi/javacall/javacv/target/classes/com/googlecode/javacv/cpp/opencv_adapters.h:132:67: error: ‘struct cv::Ptr<CvFileStorage>’ has no member named ‘addref’

 Step 2

Started Debugging, no idea from where error is thrown so decided I should rely on the forum, Posted and got the first reply from Samuel that i am using a later version of Javacv and it needs the latest version of OpenCv 3.0.

Tried to see if there is anywhere else a tutorial for OpenCv3.0,couldn't find any.

Eventually settled to compile it myself and ordeal starts.

Step 3

According to Samuel, I need to build the javacpp-presets before I build the javacpp and javacv. A quick look into the GitHub Code


I see the openCV module in there and decided i will start from there. So went into the OpenCV Folder and guess what from java background everything looks cryptic (at least for me at that time). 

So tried running the Cppbuild.sh and got an error platform not supported. A little research and i understood current make files doesnt support linux-arm platform which Raspberry Pi unfortunately is. 

Step 4

Make the Build files compatible for the "Linux File". 


Steps for Building OpenCv on Raspberry Pi
---------------------------------------------------

Install the Following packages.

If some packages are missing skip it for now and please comment so that I can update. I did found a few broken or not needed but i couldn't jot down when i was doing the build.

    • sudo apt-get update
    • sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3
    • sudo apt-get install libpnglite-dev libpngwriter0-dev libpngwriter0c2 zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev
    • sudo apt-get install libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev
    • sudo apt-get install libavcodec52 libavformat52 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev
    • sudo apt-get install libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils
    • sudo apt-get install swig libv4l-0 libv4l-dev
    • sudo apt-get install libpng-dev libjpeg-dev libxxf86vm1 libxxf86vm-dev libxi-dev libxrandr-dev
    • sudo apt-get install mesa-common-dev
    • sudo apt-get install mesa-utils-extra libgl1-mesa-dev libglapi-mesa
    • sudo apt-get install libgles2-mesa-dev
    • sudo apt-get install freeglut3 freeglut3-dbg freeglut3-dev libmgl-glut5
    • sudo apt-get install libxmu-dev libxi-dev
    • sudo apt-get install libudev-dev

  • Clone the javacpp-presets


  • I modified the make file in Opencv to make it compatible for Linux-arm. it is checked in under this project temporarily.

  • Replace the file in the Opencv Folder.
  • Initiate the build using ./cppbuild.sh install. 
  • Once Complete run sudo ldconfig
  • If u dont want to compile take the jars from the below link else continue to next step
  • Do a maven compile and install mvn clean install -DskipTests -Dplatform.name=linux-arm
That makes it done for the OpenCv.

If you don't want to compile, can download the latest from this link.


Comments

  1. Thanks for getting the build to work! Any luck with getting the rest of the javacpp-presets elements working such as ffmpeg?

    ReplyDelete
    Replies
    1. Hey sorry for late reply... i will upload the rest

      Delete
  2. Hi Aravind, I am getting an error that avutil is not found here.(org.bytedeco.javacpp.avutil.class) . Any ideas ? Which package should have this class?

    ReplyDelete
  3. Libraries not found: libpngwriter0-dev libpngwriter0c2 libavcodec52 libavformat52 mesa-utils-extra.

    ReplyDelete
    Replies
    1. Check this out

      http://raspberrypi.stackexchange.com/questions/1888/error-in-installing-opencv-on-raspberry-pi

      Delete
  4. Hi Aravind,
    I tried this yesterday and after installing the dependencies and running 'sudo ./cppbuild.sh install' in /opt/javacpp-presets (with your new build scipt), unfortunately the build of 3.0.0 in javacpp-presets terminates with an error:

    opencore-amr-0.1.3/test/amrwb-dec.c
    opencore-amr-0.1.3/test/linkboth.c

    gzip: stdin: not in gzip format
    tar: Child returned status 1
    tar: Error is not recoverable: exiting now

    Any ideas?

    Thanks and regards,
    Dave

    ReplyDelete

Post a Comment

Popular posts from this blog

'jasypt.encryptor.password' or one of ['jasypt.encryptor.privateKeyString', 'jasypt.encryptor.privateKeyLocation'] must be provided for Password-based or Asymmetric encryption

Field or property 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - Spring Batch

java.security.spec.InvalidKeySpecException: Only RSAPrivate(Crt)KeySpec and PKCS8EncodedKeySpec supported for RSA private keys