【发布时间】:2020-10-16 10:22:11
【问题描述】:
我目前正在使用 OpenCV 来检测图像中的人脸。而且我也在尝试检测这张脸是否是侧面姿势的脸。基本上我只需要得到直脸图像。所以我使用haarcascade_profileface.xml 进行人脸检测。以下是我正在使用的代码,
try {
faceDetector.load("haarcascade_profileface.xml");
Mat image = Imgcodecs.imread(imageName);
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
// Creating a rectangular box showing faces detected
for (Rect rect: faceDetections.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 0, 255), 3);
}
if (faceDetections.toArray().length == 0) {
Core.flip(image, image, 1);
faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
// Creating a rectangular box showing faces detected
for (Rect rect: faceDetections.toArray()) {
Imgproc.rectangle(image, new Point(rect.x, rect.y),
new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 0, 255), 3);
}
return faceDetections.toArray().length == 0;
}
} catch (Exception ex) {
ex.printStackTrace();
}
所以我通过翻转图像来检查图像中的脸是左侧还是右侧。我面临的问题是此轮廓人脸检测的准确性。因为我看到一些好的直脸图像也被检测为侧面。所以我错过了好的图像。如何提高此检测的准确性?
【问题讨论】:
标签: java opencv face-detection