openCV人脸识别

来源:互联网 发布:起重吊装常用数据手册 编辑:程序博客网 时间:2024/06/02 12:05
class DetectFaceDemo {
public void run() {
System.out.println("\nRunning DetectFaceDemo");


// Create a face detector from the cascade file in the resources
// directory.
// CascadeClassifier faceDetector = new
// CascadeClassifier(getClass().getResource("./lbpcascade_frontalface.xml").getPath());
CascadeClassifier faceDetector = new CascadeClassifier(
"F:\\opencv\\sources\\data\\lbpcascades\\lbpcascade_frontalface.xml");
// Mat image =
// Highgui.imread(getClass().getResource("/lena.png").getPath());
Mat image = Highgui.imread("F:\\android\\OpenCvTest\\person.jpg");


// Detect faces in the image.
// MatOfRect is a special container class for Rect.
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image, faceDetections);


System.out.println(String.format("Detected %s faces",
faceDetections.toArray().length));


// Draw a bounding box around each face.
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));
}


// Save the visualized detection.
String filename = "test.png";
System.out.println(String.format("Writing %s", filename));
Highgui.imwrite(filename, image);
}
}


public class HelloOpenCV {
public static void main(String[] args) {
System.out.println("Hello, OpenCV");


// Load the native library.
// System.loadLibrary("opencv");
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new DetectFaceDemo().run();
}
}
0 0
原创粉丝点击