[英]How to improve profile face detection in OpenCV using Java
我目前正在使用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();
}
所以我通过翻转图像来检查图像中的脸是左侧还是右侧。 我面临的问题是此轮廓人脸检测的准确性。 因为我看到一些好的直脸图像也被检测为侧面。 所以我错过了好的图像。 如何提高此检测的准确性?
您可以检查脸部是否有 2 只眼睛。 如果它有一个它的配置文件。 您只需要下载haarcascade_eye.xml
。 接下来使用新的CascadeClassifier
object 作为眼睛,您可以找到它们。 像这样的东西:
CascadeClassifier eyeDetector = new CascadeClassifier(FaceDetector.class.getResource("haarcascade_eye.xml").getPath());
MatOfRect eyeDetections = new MatOfRect();
//Result list
eyeDetector.detectMultiScale(image, eyeDetections);
eyeDetections.toArray();
int noEyes = eyeDetections[0].length;
if (noEyes < 2){
//profile
}
https://pythonprogramming.net/haar-cascade-face-eye-detection-python-opencv-tutorial/参考此链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.