feat: initial testgin for face detection
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -21,6 +21,11 @@
|
|||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openpnp</groupId>
|
||||||
|
<artifactId>opencv</artifactId>
|
||||||
|
<version>4.9.0-0</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit-jupiter</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
|||||||
@@ -1,7 +1,19 @@
|
|||||||
package com.example.facetracker;
|
package com.example.facetracker;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.opencv.core.Mat;
|
||||||
|
import org.opencv.core.MatOfRect;
|
||||||
|
import org.opencv.core.Rect;
|
||||||
|
import org.opencv.core.Scalar;
|
||||||
|
import org.opencv.core.Size;
|
||||||
|
import org.opencv.imgcodecs.Imgcodecs;
|
||||||
|
import org.opencv.imgproc.Imgproc;
|
||||||
|
import org.opencv.objdetect.CascadeClassifier;
|
||||||
|
import org.opencv.objdetect.Objdetect;
|
||||||
|
|
||||||
|
import nu.pattern.OpenCV;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for simple App.
|
* Unit test for simple App.
|
||||||
@@ -15,4 +27,41 @@ public class AppTest {
|
|||||||
public void testApp() {
|
public void testApp() {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Tracker {
|
||||||
|
private CascadeClassifier faceCascade;
|
||||||
|
|
||||||
|
public Tracker() {
|
||||||
|
faceCascade = new CascadeClassifier();
|
||||||
|
faceCascade.load("src/test/resources/haarcascade_frontalface_alt.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rect[] detect(Mat img) {
|
||||||
|
MatOfRect faces = new MatOfRect();
|
||||||
|
long min = Math.round(0.1 * img.width());
|
||||||
|
faceCascade.detectMultiScale(img, faces, 1.1, 3, Objdetect.CASCADE_SCALE_IMAGE, new Size(min, min));
|
||||||
|
return faces.toArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testImage() {
|
||||||
|
OpenCV.loadLocally();
|
||||||
|
Tracker tracker = new Tracker();
|
||||||
|
Mat img = Imgcodecs.imread("src/test/resources/20250809_151039_preview.jpeg");
|
||||||
|
Rect[] facesArray = tracker.detect(img);
|
||||||
|
for (Rect face : facesArray) {
|
||||||
|
Imgproc.rectangle(img, face, new Scalar(0, 255, 0), 2);
|
||||||
|
}
|
||||||
|
Imgcodecs.imwrite("out.jpg", img);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Test
|
||||||
|
public void testVideo() {
|
||||||
|
OpenCV.loadLocally();
|
||||||
|
VideoCapture videoCapture = new VideoCapture("src/test/resources/20250718_205627.mp4");
|
||||||
|
VideoWriter writer = new VideoWriter("out.mp4", VideoWriter.fourcc('M', 'P', '4', 'V'), 30, new Size(640, 480));
|
||||||
|
|
||||||
|
} */
|
||||||
}
|
}
|
||||||
|
|||||||
24350
src/test/resources/haarcascade_frontalface_alt.xml
Normal file
24350
src/test/resources/haarcascade_frontalface_alt.xml
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user