-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathfaceDetectionOpenCV.java
More file actions
33 lines (28 loc) · 1.16 KB
/
faceDetectionOpenCV.java
File metadata and controls
33 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package id.akdev.jopencv;
import org.opencv.core.Core;
import org.opencv.core.Scalar;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
public class MainProgram{
public static void main(String[] args){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat gambar = Imgcodecs.imread("images/gambar2.png");
CascadeClassifier cc = new CascadeClassifier("xml/lbpcascade_frontalface.xml");
MatOfRect faceDetection = new MatOfRect();
cc.detectMultiScale(gambar, faceDetection);
for(Rect rect: faceDetection.toArray()){
Imgproc.rectangle(gambar, new Point(rect.x , rect.y),
new Point(rect.x + rect.width,rect.y + rect.height),
new Scalar(0, 255, 0), 2);
}
Imgcodecs.imwrite("images/gambarHasil.png", gambar);
HighGui.imshow("Jumlah wajah terdeteksi : " + faceDetection.toArray().length + " wajah", gambar);
HighGui.waitKey();
}
}