openCV and Java - Face Detection

37
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İ

Transcript of openCV and Java - Face Detection

Page 1: openCV and Java - Face Detection

OpenCV and JavaYRD.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İ

Page 2: openCV and Java - Face Detection

Contents

� Install OpenCV

� Test OpenCV Lib

� Face Detection App.

� mainGUI Class

� detectFace Class

Page 3: openCV and Java - Face Detection

Download and install – Building

From Source

� OpenCV SourceForge repository.

� http://sourceforge.net/projects/opencvlibrary/files/opencv-win/

Page 4: openCV and Java - Face Detection

Download and install – Binary Install

� http://opencv.org/downloads.html

� Windows users can 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.

Page 5: openCV and Java - Face Detection

Download and Install – Binary Install

Page 6: openCV and Java - Face Detection

Tutorials and 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

Page 7: openCV and Java - Face Detection

Configuring Eclipse

� we will define OpenCV as a user library in Eclipse, so we can reuse the configuration for any project. Launch Eclipse and select Window –> Preferences from the menu.

Page 8: openCV and Java - Face Detection

Configuring Eclipse

� Navigate under Java –> Build Path –> User Libraries and click New....

Page 9: openCV and Java - Face Detection

Configuring Eclipse

� Enter a name, e.g. OpenCV-3.0.0, for your new library.

Page 10: openCV and Java - Face Detection

Configuring Eclipse

� Now select your new user library and click Add External JARs....

Page 11: openCV and Java - Face Detection

Configuring Eclipse� Browse through C:\opencv\build\java\ and select opencv-246.jar. After adding

the jar, extend the opencv-300.jar and select Native library location and press Edit....

Page 12: openCV and Java - Face Detection

Configuring Eclipse

� After adding the jar, extend the opencv-300.jar and select Native library location and press Edit....

Page 13: openCV and Java - Face Detection

Configuring Eclipse

� Select External Folder... and 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.

Page 14: openCV and Java - Face Detection

Configuring Eclipse

� Your user library configuration should look like this:

� Done ☺

Page 15: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� Now start creating a new Java project.

Page 16: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� Write the Project name

Page 17: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� On the Java Settings step, under Libraries tab, select Add Library->User Library... and select OpenCV-3.0.0, then click Finish.

Page 18: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� Libraries should look like this:

Page 19: openCV and Java - Face Detection

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.

Page 20: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� Here is a starter code for your convenience:

Page 21: openCV and Java - Face Detection

Testing the configuration on a new

Java project

� When you run the code you should see 3x3 identity matrix as output.

� 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. Enjoy your powerful, less painful development environment :)

� Updated version of http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/java_eclipse.html#java-eclipse

� Author: Barış Evrim Demiröz

� A tutorial on how to use OpenCV Java with Eclipse.

Page 22: openCV and Java - Face Detection

Camera Control Using Java and

OpenCV

Page 23: openCV and Java - Face Detection

Camera Control Using Java and

OpenCV – Add OpenCV-3.0.0 Lib

� Press Next button

� Select Libraries

Page 24: openCV and Java - Face Detection

Camera Control Using Java and

OpenCV – Add OpenCV-3.0.0 Lib

� You can also add librariesafter create the Project byusing "Project Properties"

Page 25: openCV and Java - Face Detection

mainGUI Class

Page 26: openCV and Java - Face Detection

mainGUI Class

Page 27: openCV and Java - Face Detection

detectFace Class

Page 28: openCV and Java - Face Detection

Face Detection

Page 29: openCV and Java - Face Detection

Face Detection – Default

Constructor

Page 30: openCV and Java - Face Detection

Face Detection

Page 31: openCV and Java - Face Detection

Face Detection

� // Create a face detector from the cascade file in the resources directory.

� // MatOfRect is a special container class for Rect.

� // Detect faces on webcam

Page 32: openCV and Java - Face Detection

Face Detection

Page 33: openCV and Java - Face Detection

Face Detection

� // Draw a bounding box around each face.

Page 34: openCV and Java - Face Detection

Face Detection – Convert openCV

MAT file to BufferedImage

Page 35: openCV and Java - Face Detection

Face Detection - Save the

screenshot.

Page 36: openCV and Java - Face Detection

Face Detection

Page 37: openCV and Java - Face Detection

Questions