opencv and java - face detection
TRANSCRIPT
![Page 1: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/1.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/2.jpg)
Contents
� Install OpenCV
� Test OpenCV Lib
� Face Detection App.
� mainGUI Class
� detectFace Class
![Page 3: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/3.jpg)
Download and install – Building
From Source
� OpenCV SourceForge repository.
� http://sourceforge.net/projects/opencvlibrary/files/opencv-win/
![Page 4: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/5.jpg)
Download and Install – Binary Install
![Page 6: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/6.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/7.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/8.jpg)
Configuring Eclipse
� Navigate under Java –> Build Path –> User Libraries and click New....
![Page 9: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/9.jpg)
Configuring Eclipse
� Enter a name, e.g. OpenCV-3.0.0, for your new library.
![Page 10: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/10.jpg)
Configuring Eclipse
� Now select your new user library and click Add External JARs....
![Page 11: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/11.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/12.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/13.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/14.jpg)
Configuring Eclipse
� Your user library configuration should look like this:
� Done ☺
![Page 15: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/15.jpg)
Testing the configuration on a new
Java project
� Now start creating a new Java project.
![Page 16: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/16.jpg)
Testing the configuration on a new
Java project
� Write the Project name
![Page 17: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/17.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/18.jpg)
Testing the configuration on a new
Java project
� Libraries should look like this:
![Page 19: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/19.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/20.jpg)
Testing the configuration on a new
Java project
� Here is a starter code for your convenience:
![Page 21: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/21.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/22.jpg)
Camera Control Using Java and
OpenCV
![Page 23: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/23.jpg)
Camera Control Using Java and
OpenCV – Add OpenCV-3.0.0 Lib
� Press Next button
� Select Libraries
![Page 24: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/24.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/25.jpg)
mainGUI Class
![Page 26: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/26.jpg)
mainGUI Class
![Page 27: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/27.jpg)
detectFace Class
![Page 28: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/28.jpg)
Face Detection
![Page 29: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/29.jpg)
Face Detection – Default
Constructor
![Page 30: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/30.jpg)
Face Detection
![Page 31: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/31.jpg)
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](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/32.jpg)
Face Detection
![Page 33: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/33.jpg)
Face Detection
� // Draw a bounding box around each face.
![Page 34: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/34.jpg)
Face Detection – Convert openCV
MAT file to BufferedImage
![Page 35: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/35.jpg)
Face Detection - Save the
screenshot.
![Page 36: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/36.jpg)
Face Detection
![Page 37: openCV and Java - Face Detection](https://reader034.vdocuments.site/reader034/viewer/2022042501/587006fa1a28ab427f8b64e7/html5/thumbnails/37.jpg)
Questions