【发布时间】:2014-04-16 04:59:12
【问题描述】:
我遵循在线教程并设法编写了一个像这样的简单课程:
public class FaceDetector
{
public static void detect(String imageFile) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.out.println("\nRunning FaceDetector");
CascadeClassifier faceDetector = new CascadeClassifier(FaceDetector.class.getResource("haarcascade_frontalface_alt.xml").getPath());
Mat image = Highgui.imread(imageFile);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
int faceCount = faceDetections.toArray().length;
System.out.println(String.format("Detected %s faces", faceCount));
for (Rect rect : faceDetections.toArray()) {
Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
String filename = imageFile+"_output.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}
但是,我已经用 200 多张个人资料图片进行了尝试,但它无法检测到一张。由于它会原封不动地重写图像文件,因此我知道它可以正确读取图像。它没有给出任何错误。我现在该怎么办?任何重定向?我应该在哪里阅读?我错过了什么?
【问题讨论】:
-
尝试:
faceDetector.isOpened()看看是否找到了级联 -
注意:我也试过 haarcascade_frontalface_default.xml 作为分类器
-
感谢它的工作。以防遇到类似问题的人;我已经在文件夹名称分类器下移动了 xml,并像这样创建了 faceDetector: CascadeClassifier faceDetector = new CascadeClassifier(); faceDetector.load("分类器/haarcascade_frontalface_alt.xml");
-
再次强调,不要将正面级联与个人资料图像一起使用。尝试 lbpcascade_profileface.xml 或类似的
标签: java opencv face-detection