OpenCV and Java
YRD.DOÇ.DR. CELAL MURAT KANDEMİR
ESKİŞEHİR OSMANGAZİ ÜNİVERSİTESİ EĞİTİM FAKÜLTESİ
BİLGİSAYAR VE ÖĞRETİM TEKNOLOJİLERİ EĞİTİMİ
Contents
€ Install OpenCV
€ Test OpenCV Lib
€ Face Detection App.
€ mainGUI Class
€ detectFace Class
Download a n d install – Building
From Source
€ OpenCV SourceForge repository.
€ http://sourceforge.net/projects/opencvl
ibrary/files/opencv-win/
Download a n d install – Binary Install
€ http://opencv.org/downloads.html
€ Windows users c a n find the prebuilt files needed for Java
development in the opencv/build/java/ folder inside the package.
For other OSes it’s required to build OpenCV from sources.
Download a n d Install – Binary Install
Tutorials a n d Documentation
€ http://opencv-java-tutorials.readthedocs.org/en/latest/02 -first-java-application-with-opencv.html
€ http://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html
€ http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/java_eclipse.html#java -eclipse
Configuring Eclipse
€ we will define OpenCV as a user
library in Eclipse, so we c a n reuse the
configuration for any project. Launch
Eclipse a n d select Window –>
Preferences from the menu.
Configuring Eclipse
€ Navigate under Java –> Build Path –>
User Libraries a n d click New....
Configuring Eclipse
€ Enter a name, e.g. OpenCV-3.0.0, for
your new library.
Configuring Eclipse
€ Now select your new user library a n d
click A d d External JARs....
Configuring Eclipse
€ Browse through C : \ o p e n c v \ b u i l d \ j a v a \ a n d select opencv-246.jar. After adding
the jar, extend the opencv-300.jar a n d select Native library location a n d press
Edit....
Configuring Eclipse
€ After adding the jar, extend the
opencv-300.jar a n d select Native
library location a n d press Edit....
Configuring Eclipse
€ Select External Folder... a n d browse to select the folder C:\OpenCV-
2.4.6\build\java\x64. If you have a 32-bit system you need to select the x86 folder
instead of x64.
Configuring Eclipse
€ Your user library configuration
should look like this:
€ Done ☺
Testing the configuration on a new
Java project
€ Now start creating a new Java
project.
Testing the configuration on a new
Java project
€ Write the Project name
Testing the configuration on a new
Java project
€ On the Java Settings step, under Libraries tab, select A d d Library->User Library...
a n d select OpenCV-3.0.0, then click Finish.
Testing the configuration on a new
Java project
€ Libraries should look like this:
Testing the configuration on a new
Java project
€ Now you have created and
configured a new Java project it is
time to test it. Create a new java file.
Testing the configuration on a new
Java project
€ Here is a starter c o d e for your
convenience:
Testing the configuration on a new
Java project
€ When you run the c o d e you should see
3x3 identity matrix as output.
€ That is it, whenever you start a new
project just a d d the OpenCV user library
that you have defined to your project
a n d you are g o o d to go. Enjoy your
powerful, less painful development
environment :)
€ Updated version of
http://docs.opencv.org/2.4/doc/tutorial
s/introduction/java_eclipse/java_eclipse
.html#java-eclipse
€ Author: Barış Evrim Demiröz
€ A tutorial on h o w to use OpenCV Java
with Eclipse.
Camera Control Using Java a n d
OpenCV
Camera Control Using Java a n d
OpenCV – A d d OpenCV-3.0.0 Lib
€ Press Next button
€ Select Libraries
Camera Control Using Java a n d
OpenCV – A d d OpenCV-3.0.0 Lib
€ You c a n also a d d libraries
after create the Project by
using "Project Properties"
mainGUI Class
mainGUI Class
detectFace Class
Face Detection
Face Detection –Default
Constructor
Face Detection
Face Detection
€ / / Create a f a c e detector from the cascade file in the resources directory.
€ / / MatOfRect is a special container class for Rect.
€ / / Detect faces on w e b c a m
Face Detection
Face Detection
€ / / Draw a bounding box around e a c h face.
Face Detection – Convert openCV
MAT file to BufferedImage
Face Detection - Save the
screenshot.
Face Detection
Questions