Monday, October 20, 2014

Using OpenCV Java with Eclipse in Linux

         First, obtain a fresh release of OpenCV from download page and extract it under a simple location like /home/(your username)/opencv-2.4.9 .I am using version 2.4.9, but the steps are more or less the same for other versions.
  • Window ->Preferences ->Java ->Build Path -User Libraries ->Press New 
  • Set lib name and click Ok.
  • Add External JARs; browse through ~/OpenCV/ .... /build/bin andopencv-249.jar; press Ok
  • Select Native library location and press Edit; press External folder; browse through ~/OpenCV/ .... /build/lib and press Ok; press Ok, press Ok
  • restart Eclipse

Testing the configuration on a new Java project

  •  Now start creating a new Java project.
 
  •  Project -> Properties -> Add Library -> User Library (press Next) - > chose OpenCV 2.6.4 -> press finish
  •  File -> New -> Class -> press Finish
  •  Paste this code into a newly created class and press Run
          
          That is it, whenever you start a new project just add the OpenCV user library that you have defined to your project and you are good to go.Thank you for reading.