以下是在OpenCV中检测面部并在ace区域周围绘制一个矩形的代码。
class FaceDetect {
public void run() {
CascadeClassifier faceDetector = new CascadeClassifier("C:\\Users\\powerohit\\workspace\\OpenCV\\lbpcascade_frontalface.xml");
Mat image = Imgcodecs.imread("C:\\Users\\powerohit\\workspace\\OpenCV\\rohit.jpg");
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);
System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
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, 255, 0));
}
String filename = "faceDetection1.png";
System.out.println(String.format("Writing %s", filename));
Imgcodecs.imwrite(filename, image);
}
}
public class HelloOpenCV {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new FaceDetect().run();
}
}
现在我必须加密矩形中的面部区域。我已经开发了一个加密数据的代码,但我需要将面部区域提取到一个数组中,然后对其进行加密并将其放回到面部区域。
如何获取图像的面部区域?